Improve accessibility functionality (#64)
* Initial commit * fetching accessibility of dock
This commit is contained in:
@@ -628,12 +628,15 @@ def _create_axui_node(node, nodes: set = None, depth: int = 0, bbox: tuple = Non
|
|||||||
node["kCGWindowBounds"]["Y"] + node["kCGWindowBounds"]["Height"]
|
node["kCGWindowBounds"]["Y"] + node["kCGWindowBounds"]["Height"]
|
||||||
)
|
)
|
||||||
app_ref = ApplicationServices.AXUIElementCreateApplication(node["kCGWindowOwnerPID"])
|
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"]
|
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]
|
node = app_wins_ref[0]
|
||||||
|
|
||||||
error_code, attr_names = ApplicationServices.AXUIElementCopyAttributeNames(node, None)
|
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")})
|
return jsonify({"AT": lxml.etree.tostring(xml_node, encoding="unicode")})
|
||||||
|
|
||||||
elif os_name == "Darwin":
|
elif os_name == "Darwin":
|
||||||
|
# TODO: Add Dock and MenuBar
|
||||||
xml_node = lxml.etree.Element("desktop", nsmap=_accessibility_ns_map_macos)
|
xml_node = lxml.etree.Element("desktop", nsmap=_accessibility_ns_map_macos)
|
||||||
|
|
||||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
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 = [
|
futures = [
|
||||||
executor.submit(_create_axui_node, wnd, None, 0) for wnd in
|
executor.submit(_create_axui_node, wnd, None, 0)
|
||||||
[win for win in
|
for wnd in foreground_windows + dock_info
|
||||||
Quartz.CGWindowListCopyWindowInfo(
|
]
|
||||||
(Quartz.kCGWindowListExcludeDesktopElements | Quartz.kCGWindowListOptionOnScreenOnly),
|
|
||||||
Quartz.kCGNullWindowID, ) if
|
|
||||||
win["kCGWindowLayer"] == 0 and win["kCGWindowOwnerName"] != "Window Server"
|
|
||||||
]]
|
|
||||||
|
|
||||||
for future in concurrent.futures.as_completed(futures):
|
for future in concurrent.futures.as_completed(futures):
|
||||||
xml_tree = future.result()
|
xml_tree = future.result()
|
||||||
|
|||||||
Reference in New Issue
Block a user