TheDuriel / MagicMacros

Godot Addon for enhanced autocomplete and code snippets
MIT License
53 stars 4 forks source link

Macros not working with floating windows. #8

Closed Taksharya333 closed 1 week ago

Taksharya333 commented 1 week ago

I mainly uses my second monitor with floating code editor, but when I tested this addon wasn't working with floating window. So checked the code and found the _attach_input_catchers(): which was responsible for attaching the tab to the window, and while checking I also find out that the get_embedded_subwindows was not working at all. It was always returning empty array but I don't think that was supposed to make it work with floating window and since I am also a novice I wasn't aware of much functions of Godot's engine so with the help of Godot's community and the geniuses there. I found a way to make it work: I would like to give credit to the helper but I don't know if they would prefer it. Here is the code that I changed: Old:

func _attach_input_catchers() -> void:
    var root_window: Window = get_window()
    if not root_window in _input_catchers:
        _input_catchers[root_window] = MagicMacrosInputCatcher.new(root_window)
        _input_catchers[root_window].tab_pressed.connect(_on_tab_pressed)
           print("MagicMacros: Main window hooked.")
    var subwindows: Array[Window] = root_window.get_embedded_subwindows()
    for window: Window in subwindows:
        if not (window in _input_catchers):
            _input_catchers[window] = MagicMacrosInputCatcher.new(window)
            _input_catchers[window].tab_pressed.connect(_on_tab_pressed)
            print("MagicMacros: Sub window hooked.")

New:

func _attach_input_catchers() -> void:
    var windows: Array[Window]
    for window_id in DisplayServer.get_window_list():
        var instance_id: int = DisplayServer.window_get_attached_instance_id(window_id)
        var window: Window = instance_from_id(instance_id)
        windows.append(window)
    for window: Window in windows:
        if not (window in _input_catchers):
            _input_catchers[window] = MagicMacrosInputCatcher.new(window)
            _input_catchers[window].tab_pressed.connect(_on_tab_pressed)
            print("MagicMacros: Window hooked.")
TheDuriel commented 1 week ago

Interesting! I wonder why they sometimes don't count as embedded. I had tested it at least once >.<

Will include in the next version! Thanks a bunch