diff --git a/desktop_env/server/main.py b/desktop_env/server/main.py index b1e1c65..f0d8a6d 100644 --- a/desktop_env/server/main.py +++ b/desktop_env/server/main.py @@ -628,12 +628,15 @@ def _create_axui_node(node, nodes: set = None, depth: int = 0, bbox: tuple = Non node["kCGWindowBounds"]["Y"] + node["kCGWindowBounds"]["Height"] ) app_ref = ApplicationServices.AXUIElementCreateApplication(node["kCGWindowOwnerPID"]) - error_code, app_wins_ref = ApplicationServices.AXUIElementCopyAttributeValue(app_ref, "AXWindows", None) - if error_code: - logger.error("MacOS parsing %s encountered Error code: %d", app_ref, error_code) attribute_dict["name"] = node["kCGWindowOwnerName"] - + if attribute_dict["name"] != "Dock": + error_code, app_wins_ref = ApplicationServices.AXUIElementCopyAttributeValue( + app_ref, "AXWindows", None) + if error_code: + logger.error("MacOS parsing %s encountered Error code: %d", app_ref, error_code) + else: + app_wins_ref = [app_ref] node = app_wins_ref[0] error_code, attr_names = ApplicationServices.AXUIElementCopyAttributeNames(node, None) @@ -777,17 +780,28 @@ def get_accessibility_tree(): return jsonify({"AT": lxml.etree.tostring(xml_node, encoding="unicode")}) elif os_name == "Darwin": + # TODO: Add Dock and MenuBar xml_node = lxml.etree.Element("desktop", nsmap=_accessibility_ns_map_macos) with concurrent.futures.ThreadPoolExecutor() as executor: + foreground_windows = [ + win for win in Quartz.CGWindowListCopyWindowInfo( + (Quartz.kCGWindowListExcludeDesktopElements | + Quartz.kCGWindowListOptionOnScreenOnly), + Quartz.kCGNullWindowID + ) if win["kCGWindowLayer"] == 0 and win["kCGWindowOwnerName"] != "Window Server" + ] + dock_info = [ + win for win in Quartz.CGWindowListCopyWindowInfo( + Quartz.kCGWindowListOptionAll, + Quartz.kCGNullWindowID + ) if win.get("kCGWindowName", None) == "Dock" + ] + futures = [ - executor.submit(_create_axui_node, wnd, None, 0) for wnd in - [win for win in - Quartz.CGWindowListCopyWindowInfo( - (Quartz.kCGWindowListExcludeDesktopElements | Quartz.kCGWindowListOptionOnScreenOnly), - Quartz.kCGNullWindowID, ) if - win["kCGWindowLayer"] == 0 and win["kCGWindowOwnerName"] != "Window Server" - ]] + executor.submit(_create_axui_node, wnd, None, 0) + for wnd in foreground_windows + dock_info + ] for future in concurrent.futures.as_completed(futures): xml_tree = future.result()