Skip to content

Commit aabca37

Browse files
Copilotlijy91
andauthored
[Linux] Implement AccessibilityManager class (#9)
* Initial plan * Implement AccessibilityManager for Linux platform Co-authored-by: lijy91 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: lijy91 <[email protected]>
1 parent 498f23b commit aabca37

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include "../../accessibility_manager.h"
2+
3+
#include <cstdlib>
4+
#include <iostream>
5+
6+
// Import GTK headers for accessibility support
7+
#include <gtk/gtk.h>
8+
#include <glib.h>
9+
10+
namespace nativeapi {
11+
12+
void AccessibilityManager::Enable() {
13+
// On Linux, accessibility is primarily handled by AT-SPI (Assistive Technology Service Provider Interface)
14+
// Applications typically don't need to explicitly "enable" accessibility - it's handled by the system
15+
// However, we can ensure GTK accessibility features are available
16+
17+
// Initialize GTK if not already initialized (for accessibility bridge)
18+
if (!gdk_display_get_default()) {
19+
// Try to initialize GTK silently if not already done
20+
gtk_init_check(nullptr, nullptr);
21+
}
22+
23+
// The accessibility bridge in GTK is automatically enabled when accessibility is needed
24+
// No explicit action needed - this is a no-op on Linux as accessibility is system-managed
25+
}
26+
27+
bool AccessibilityManager::IsEnabled() {
28+
// Check if accessibility features are enabled on the Linux system
29+
30+
// Method 1: Check if AT-SPI accessibility bus is running
31+
// This is the most reliable way to detect if accessibility is active
32+
const char* at_spi_bus = g_getenv("AT_SPI_BUS");
33+
if (at_spi_bus && strlen(at_spi_bus) > 0) {
34+
return true;
35+
}
36+
37+
// Method 2: Check for common accessibility environment variables
38+
const char* accessibility_enabled = g_getenv("GNOME_ACCESSIBILITY");
39+
if (accessibility_enabled && g_ascii_strcasecmp(accessibility_enabled, "1") == 0) {
40+
return true;
41+
}
42+
43+
// Method 3: Check if screen reader (Orca) is running
44+
// This is a fallback method for older systems
45+
if (system("pgrep -x orca > /dev/null 2>&1") == 0) {
46+
return true;
47+
}
48+
49+
// Method 4: Check GTK accessibility settings if available
50+
// Some desktop environments set this when accessibility is enabled
51+
const char* gtk_modules = g_getenv("GTK_MODULES");
52+
if (gtk_modules && strstr(gtk_modules, "gail") != nullptr) {
53+
return true;
54+
}
55+
56+
// If none of the above methods detect accessibility, assume it's disabled
57+
return false;
58+
}
59+
60+
} // namespace nativeapi

0 commit comments

Comments
 (0)