Skip to content

Commit

Permalink
Add WinWaitActive / WinWaitNotActive
Browse files Browse the repository at this point in the history
  • Loading branch information
phil294 committed Jul 20, 2023
1 parent c22483c commit 4d2b6a9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -55,7 +55,7 @@ AHK_X11 can be used completely without a terminal. You can however if you want u
<details><summary><strong>CLICK TO SEE WHICH COMMANDS ARE IMPLEMENTED AND WHICH ARE MISSING</strong>. Note however that this is not very representative. For example, no `Gui` sub command is included in the listing. For a better overview on what is already done, skim through the <a href="https://phil294.github.io/AHK_X11"><b>FULL DOCUMENTATION HERE</b></a>.</summary>

```diff
DONE ?% (117/220):
DONE ?% (119/220):
+ Else, { ... }, Break, Continue, Return, Exit, GoSub, GoTo, IfEqual, Loop, SetEnv, Sleep, FileCopy,
+ SetTimer, WinActivate, MsgBox, Gui, SendRaw, #Persistent, ExitApp,
+ EnvAdd, EnvSub, EnvMult, EnvDiv, ControlSendRaw, IfWinExist/IfWinNotExist, SetWorkingDir,
Expand All @@ -72,7 +72,7 @@ DONE ?% (117/220):
+ PixelSearch, #Include, InputBox, ClipWait, EnvSet, SetKeyDelay, SetMouseDelay, MouseClickDrag,
+ #NoTrayIcon, TrayTip, Random, Shutdown, RunAs, SoundGet, SoundSet, SoundPlay, Sort,
+ StringTrimLeft, StringTrimRight, WinMinimizeAll, WinMinimizeAllUndo, WinSetTitle, WinWait,
+ WinWaitClose
+ WinWaitClose, WinWaitActive, WinWaitNotActive

NEW ?% (9/220): (not part of spec or from a more recent version)
@@ Echo, ahk_x11_print_vars, FileRead, RegExGetPos, RegExReplace, EnvGet, Click @@
Expand All @@ -87,7 +87,7 @@ REMOVED ?% (11/220):
# AutoTrim: It's always Off. It would not differentiate between %a_space% and %some_var%.
# It's possible but needs significant work.

TO DO ?% (79/220): alphabetically
TO DO ?% (77/220): alphabetically
- BlockInput, Control, ControlFocus, ControlGet, ControlGetFocus,
- ControlMove,
- DetectHiddenText, DetectHiddenWindows, Drive, DriveGet, DriveSpaceFree,
Expand All @@ -108,8 +108,8 @@ TO DO ?% (79/220): alphabetically
- SysGet, Thread, Transform, WinActivateBottom,
- WinGetActiveStats, WinGetActiveTitle,
- WinMenuSelectItem,
- WinSet, WinWaitActive,
- WinWaitNotActive, #CommentFlag, #ErrorStdOut, #EscapeChar,
- WinSet,
- #CommentFlag, #ErrorStdOut, #EscapeChar,
- #HotkeyInterval, #HotkeyModifierTimeout, #MaxHotkeysPerInterval, #MaxMem,
- #MaxThreads, #MaxThreadsBuffer, #MaxThreadsPerHotkey, #WinActivateForce

Expand Down
9 changes: 5 additions & 4 deletions docs/index.html
Expand Up @@ -782,7 +782,7 @@ <h2>Table of contents </h2>
<a href="#WinWait.htm">WinWait</a>
</li>
<li>
<a class="tbd" href="#WinWaitActive.htm">WinWaitActive/WinWaitNotActive</a>
<a href="#WinWaitActive.htm">WinWaitActive/WinWaitNotActive</a>
</li>
<li>
<a href="#WinWaitClose.htm">WinWaitClose</a>
Expand Down Expand Up @@ -2810,15 +2810,15 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<td height="16" class="calibre4">Waits until the requested window exists.</td>
</tr>
<tr class="calibre3">
<td height="16" class="tbd calibre4"><a href="#WinWaitActive.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">WinWaitActive</a></td>
<td height="16" class="calibre4"><a href="#WinWaitActive.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">WinWaitActive</a></td>
<td height="16" class="calibre4">Waits until the requested window is active.</td>
</tr>
<tr class="calibre3">
<td height="16" class="calibre4"><a href="#WinWaitClose.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">WinWaitClose</a></td>
<td height="16" class="calibre4">Waits until the requested window does not exist.</td>
</tr>
<tr class="calibre3">
<td height="16" class="tbd calibre4"><a href="#WinWaitActive.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">WinWaitNotActive</a></td>
<td height="16" class="calibre4"><a href="#WinWaitActive.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">WinWaitNotActive</a></td>
<td height="16" class="calibre4">Waits until the requested window is not active.</td>
</tr>
<tr class="calibre3">
Expand Down Expand Up @@ -15014,7 +15014,7 @@ <h2 id="Examples">Examples</h2>
</pre>
</div>
</div>
<div class="calibreMain tbd">
<div class="calibreMain">
<div class="calibreEbookContent">
<a id="WinWaitActive.htm" href="#WinWaitActive.htm">#</a> <h2 class="calibre17">WinWaitActive / WinWaitNotActive</h2>
<hr size="2" class="calibre24" />
Expand Down Expand Up @@ -15061,6 +15061,7 @@ <h2 id="Examples">Examples</h2>
<p class="calibre8">Both of these commands will update the <a href="#LastFoundWindow.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Last Found Window</a> if a qualified window is active when the command begins.</p>
<p class="calibre8">Window titles and text are always case sensitive. Hidden windows are not detected unless <a href="#DetectHiddenWindows.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">DetectHiddenWindows</a> has been turned on.</p>
<p class="calibre8">While the command is in a waiting state, new <a href="#Threads.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">threads</a> can be launched via <a href="#Hotkeys.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">hotkey</a>, <a href="#Menu.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">custom menu item</a>, or <a href="#SetTimer.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">timer</a>.</p>
<p class="calibre8 x11">The seconds waited may not be very precise as the program internally merely does a loop with exponential back-off delay.</p>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">Related</strong></p>
<p class="calibre8"><a href="#WinWait.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">WinWait</a>, <a href="#WinWaitClose.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">WinWaitClose</a>, <a href="#IfWinExist.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">IfWinExist</a>, <a href="#IfWinActive.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">IfWinActive</a>, <a href="#SetTitleMatchMode.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetTitleMatchMode</a>, <a href="#DetectHiddenWindows.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">DetectHiddenWindows</a></p>
Expand Down
22 changes: 22 additions & 0 deletions src/cmd/x11/window/win-wait-active.cr
@@ -0,0 +1,22 @@
require "../../../util/exponential-back-off.cr"
require "./win-util"
# WinWaitActive [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]
class Cmd::X11::Window::WinWaitActive < Cmd::Base
def self.min_args; 0 end
def self.max_args; 5 end
def self.sets_error_level; true end
def run(thread, args)
seconds = args[2]?.try &.to_f?
seconds = 0.5 if seconds == 0
match_conditions = args
match_conditions.delete_at(2) if args[2]?
is_active = ::Util::ExponentialBackOff.back_off(initial_interval: 5.milliseconds, factor: 1.15, max_interval: 0.8.seconds, timeout: seconds ? seconds.seconds : nil) do
active = false
Util.match(thread, match_conditions, empty_is_last_found: true, a_is_active: false) do |win|
active = win == thread.runner.display.x_do.active_window
end
active
end
is_active ? "0" : "1"
end
end
22 changes: 22 additions & 0 deletions src/cmd/x11/window/win-wait-not-active.cr
@@ -0,0 +1,22 @@
require "../../../util/exponential-back-off.cr"
require "./win-util"
# WinWaitNotActive [, WinTitle, WinText, Seconds, ExcludeTitle, ExcludeText]
class Cmd::X11::Window::WinWaitNotActive < Cmd::Base
def self.min_args; 0 end
def self.max_args; 5 end
def self.sets_error_level; true end
def run(thread, args)
seconds = args[2]?.try &.to_f?
seconds = 0.5 if seconds == 0
match_conditions = args
match_conditions.delete_at(2) if args[2]?
is_not_active = ::Util::ExponentialBackOff.back_off(initial_interval: 5.milliseconds, factor: 1.15, max_interval: 0.8.seconds, timeout: seconds ? seconds.seconds : nil) do
not_active = false
Util.match(thread, match_conditions, empty_is_last_found: true, a_is_active: false) do |win|
not_active = win != thread.runner.display.x_do.active_window
end
not_active
end
is_not_active ? "0" : "1"
end
end

0 comments on commit 4d2b6a9

Please sign in to comment.