From 4d2b6a9815f9c45e16b75a630e09ca522b38b243 Mon Sep 17 00:00:00 2001 From: phil294 Date: Thu, 20 Jul 2023 11:02:02 +0200 Subject: [PATCH] Add WinWaitActive / WinWaitNotActive --- README.md | 10 +++++----- docs/index.html | 9 +++++---- src/cmd/x11/window/win-wait-active.cr | 22 ++++++++++++++++++++++ src/cmd/x11/window/win-wait-not-active.cr | 22 ++++++++++++++++++++++ 4 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 src/cmd/x11/window/win-wait-active.cr create mode 100644 src/cmd/x11/window/win-wait-not-active.cr diff --git a/README.md b/README.md index 6b0421a..e0f3377 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ AHK_X11 can be used completely without a terminal. You can however if you want u
CLICK TO SEE WHICH COMMANDS ARE IMPLEMENTED AND WHICH ARE MISSING. 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 FULL DOCUMENTATION HERE. ```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, @@ -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 @@ @@ -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, @@ -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 diff --git a/docs/index.html b/docs/index.html index a999f7d..a577503 100644 --- a/docs/index.html +++ b/docs/index.html @@ -782,7 +782,7 @@

Table of contents

WinWait
  • - WinWaitActive/WinWaitNotActive + WinWaitActive/WinWaitNotActive
  • WinWaitClose @@ -2810,7 +2810,7 @@

    The "Last Found" Window

    Waits until the requested window exists. - WinWaitActive + WinWaitActive Waits until the requested window is active. @@ -2818,7 +2818,7 @@

    The "Last Found" Window

    Waits until the requested window does not exist. - WinWaitNotActive + WinWaitNotActive Waits until the requested window is not active. @@ -15014,7 +15014,7 @@

    Examples

    -
    +
    #

    WinWaitActive / WinWaitNotActive


    @@ -15061,6 +15061,7 @@

    Examples

    Both of these commands will update the Last Found Window if a qualified window is active when the command begins.

    Window titles and text are always case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been turned on.

    While the command is in a waiting state, new threads can be launched via hotkey, custom menu item, or timer.

    +

    The seconds waited may not be very precise as the program internally merely does a loop with exponential back-off delay.

     

    Related

    WinWait, WinWaitClose, IfWinExist, IfWinActive, SetTitleMatchMode, DetectHiddenWindows

    diff --git a/src/cmd/x11/window/win-wait-active.cr b/src/cmd/x11/window/win-wait-active.cr new file mode 100644 index 0000000..30a9bc5 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/src/cmd/x11/window/win-wait-not-active.cr b/src/cmd/x11/window/win-wait-not-active.cr new file mode 100644 index 0000000..ef7b87e --- /dev/null +++ b/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 \ No newline at end of file