From c6ad56b700be142a19e2c96cc363dfa2cae153c1 Mon Sep 17 00:00:00 2001 From: phil294 Date: Wed, 5 Jul 2023 03:11:58 +0200 Subject: [PATCH] Add `DetectHiddenWindows` and `A_DetectHiddenWindows` ref https://github.com/phil294/vimium-everywhere/issues/3 --- docs/index.html | 8 ++++---- src/cmd/misc/detect-hidden-windows.cr | 8 ++++++++ src/cmd/x11/window/win-util.cr | 10 +++++++--- src/run/thread.cr | 4 ++++ 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 src/cmd/misc/detect-hidden-windows.cr diff --git a/docs/index.html b/docs/index.html index 9104feb..4f8f2ce 100644 --- a/docs/index.html +++ b/docs/index.html @@ -692,7 +692,7 @@

Table of contents

DetectHiddenText
  • - DetectHiddenWindows + DetectHiddenWindows
  • IfWinActive/IfWinNotActive @@ -1666,7 +1666,7 @@

    A_DetectHiddenWindows - # The current mode (On or Off) set by DetectHiddenWindows. + # The current mode (On or Off) set by DetectHiddenWindows. A_DetectHiddenText @@ -2089,7 +2089,7 @@

    The "Last Found" Window

    Determines whether invisible text in a window is "seen" for the purpose of finding the window. This affects commands such as IfWinExist and WinActivate. - DetectHiddenWindows + DetectHiddenWindows Determines whether invisible windows are "seen" by the script. @@ -13362,7 +13362,7 @@

    The "Last Found" Window

     

    -
    +
    #

    DetectHiddenWindows


    diff --git a/src/cmd/misc/detect-hidden-windows.cr b/src/cmd/misc/detect-hidden-windows.cr new file mode 100644 index 0000000..71d120e --- /dev/null +++ b/src/cmd/misc/detect-hidden-windows.cr @@ -0,0 +1,8 @@ +# DetectHiddenWindows, On|Off +class Cmd::Misc::DetectHiddenWindows < Cmd::Base + def self.min_args; 1 end + def self.max_args; 1 end + def run(thread, args) + thread.settings.detect_hidden_windows = args[0].downcase == "on" + end +end \ No newline at end of file diff --git a/src/cmd/x11/window/win-util.cr b/src/cmd/x11/window/win-util.cr index 9cd3017..ac898f2 100644 --- a/src/cmd/x11/window/win-util.cr +++ b/src/cmd/x11/window/win-util.cr @@ -23,11 +23,15 @@ class Cmd::X11::Window::Util exclude_text = match_conditions[3]? || "" current_desktop = thread.runner.display.x_do.desktop.to_i32 + # Note: This can crash with "XGetWindowProperty failed!Invalid memory access (signal 11) at address 0x0 [...] xdo_get_desktop_for_window +120 in /usr/lib/libxdo + # Which is fixed with an xdotool fork (see build/README.md) wins = thread.runner.display.x_do.search do require_all - only_visible # if not present, this can seem unpredictable and buggy to the user https://github.com/jordansissel/xdotool/issues/67#issuecomment-1193573254 - # ^ link also explains the need for specifying desktop: - desktop current_desktop + if ! thread.settings.detect_hidden_windows + only_visible # if not present, this can seem unpredictable and buggy to the user https://github.com/jordansissel/xdotool/issues/67#issuecomment-1193573254 + # ^ link also explains the need for specifying desktop: + desktop current_desktop + end if title.starts_with?("ahk_class ") # TODO: these/name etc should all be case sensitive. Maybe double filter below? How performant is querying for .name etc? window_class_name title[10..] # TODO: is this regex? how to make partial matches like ahk? diff --git a/src/run/thread.cr b/src/run/thread.cr index 6e4952a..cc2460a 100644 --- a/src/run/thread.cr +++ b/src/run/thread.cr @@ -18,6 +18,7 @@ module Run property coord_mode_mouse = CoordMode::RELATIVE property coord_mode_caret = CoordMode::RELATIVE property coord_mode_menu = CoordMode::RELATIVE + property detect_hidden_windows = false property ahk_x11_track_performance = false end @@ -213,6 +214,9 @@ module Run case var when "a_index" (@loop_stack.last?.try &.index || 0).to_s + when "a_detecthiddenwindows" + pp! @settings + @settings.detect_hidden_windows ? "On" : "Off" else nil end