Correlate foreground windows whose frame reports no bounds
- GPUI via AccessKit publishes frame extents of -1 and gives the frame's root child window-local bounds at 0,0, so every GPUI window failed foreground geometry correlation and all of its events were ignored as background: total silence under a reader that otherwise received a complete, well-formed tree. - foregroundBounds keeps a valid frame rectangle and only falls back to the root child's, which must still pass the existing same-process, exact-client-size unpositioned-window rule. - Factor the Component extents query into accessibleScreenExtents shared by the frame and root-child lookups. - Verified with GPUI's a11y example (crates/gpui/examples/a11y.rs) in a private Xvfb/i3 session: focus, value, name, and pressed announcements all spoken; foreground test suite passes.
This commit is contained in:
1 parent
a34d7e70c8
commit
e9b2e9508b
3 files changed
+82
-12
No files matched your search
@@ -144,23 +144,20 @@ func (adapter *Adapter) matchForeground(source, window *C.AtspiAccessible, id Ob
|
|||||||
adapter.foregroundRecovery = 0
|
adapter.foregroundRecovery = 0
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
component := C.atspi_accessible_get_component_iface(window)
|
rectangle, ok := accessibleScreenExtents(window)
|
||||||
if component == nil {
|
if !ok {
|
||||||
if check != nil {
|
|
||||||
check.Reason = "accessible window component unavailable"
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
bounds := C.atspi_component_get_extents(component, C.ATSPI_COORD_TYPE_SCREEN, nil)
|
|
||||||
C.g_object_unref(C.gpointer(component))
|
|
||||||
if bounds == nil {
|
|
||||||
if check != nil {
|
if check != nil {
|
||||||
check.Reason = "accessible window bounds unavailable"
|
check.Reason = "accessible window bounds unavailable"
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
rectangle := Rectangle{X: int32(bounds.x), Y: int32(bounds.y), Width: int32(bounds.width), Height: int32(bounds.height)}
|
if !rectangle.Valid() {
|
||||||
C.g_free(C.gpointer(bounds))
|
// The frame itself is unbounded; its root child may carry the
|
||||||
|
// window-local bounds foregroundBounds can correlate instead.
|
||||||
|
if child, childOK := rootChildScreenExtents(window); childOK {
|
||||||
|
rectangle = foregroundBounds(rectangle, child)
|
||||||
|
}
|
||||||
|
}
|
||||||
if check != nil {
|
if check != nil {
|
||||||
check.Bounds = rectangle
|
check.Bounds = rectangle
|
||||||
}
|
}
|
||||||
@@ -192,6 +189,36 @@ func (adapter *Adapter) matchForeground(source, window *C.AtspiAccessible, id Ob
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// accessibleScreenExtents reports the accessible's Component extents in
|
||||||
|
// screen coordinates. The returned rectangle may still be invalid (for
|
||||||
|
// example all -1) when the toolkit publishes no real bounds; ok only
|
||||||
|
// reports whether the query itself succeeded.
|
||||||
|
func accessibleScreenExtents(accessible *C.AtspiAccessible) (Rectangle, bool) {
|
||||||
|
component := C.atspi_accessible_get_component_iface(accessible)
|
||||||
|
if component == nil {
|
||||||
|
return Rectangle{}, false
|
||||||
|
}
|
||||||
|
bounds := C.atspi_component_get_extents(component, C.ATSPI_COORD_TYPE_SCREEN, nil)
|
||||||
|
C.g_object_unref(C.gpointer(component))
|
||||||
|
if bounds == nil {
|
||||||
|
return Rectangle{}, false
|
||||||
|
}
|
||||||
|
rectangle := Rectangle{X: int32(bounds.x), Y: int32(bounds.y), Width: int32(bounds.width), Height: int32(bounds.height)}
|
||||||
|
C.g_free(C.gpointer(bounds))
|
||||||
|
return rectangle, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// rootChildScreenExtents reports the screen extents of the accessible's
|
||||||
|
// first child, for frames whose own bounds are unavailable.
|
||||||
|
func rootChildScreenExtents(window *C.AtspiAccessible) (Rectangle, bool) {
|
||||||
|
child := C.atspi_accessible_get_child_at_index(window, 0, nil)
|
||||||
|
if child == nil {
|
||||||
|
return Rectangle{}, false
|
||||||
|
}
|
||||||
|
defer C.g_object_unref(C.gpointer(child))
|
||||||
|
return accessibleScreenExtents(child)
|
||||||
|
}
|
||||||
|
|
||||||
// The exception is for a native menu from the panel process, never an
|
// The exception is for a native menu from the panel process, never an
|
||||||
// arbitrary panel control or a provider claiming the panel's accessible name.
|
// arbitrary panel control or a provider claiming the panel's accessible name.
|
||||||
// Query fresh window state on the GLib owner; no popup state is retained.
|
// Query fresh window state on the GLib owner; no popup state is retained.
|
||||||
|
|||||||
@@ -53,6 +53,19 @@ func foregroundWindowMatches(client xorg.Foreground, pid int, bounds Rectangle)
|
|||||||
unpositionedWindowMatches(client, pid, bounds, inner)
|
unpositionedWindowMatches(client, pid, bounds, inner)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some toolkits publish no bounds on the accessible frame itself but give
|
||||||
|
// the frame's root child window-local bounds (GPUI via AccessKit, whose
|
||||||
|
// frame extents are all -1). A valid frame rectangle always wins; the
|
||||||
|
// child rectangle is only a candidate and must still pass
|
||||||
|
// foregroundWindowMatches, where its 0,0 origin routes to
|
||||||
|
// unpositionedWindowMatches (same process, exact client size).
|
||||||
|
func foregroundBounds(frame, rootChild Rectangle) Rectangle {
|
||||||
|
if frame.Valid() {
|
||||||
|
return frame
|
||||||
|
}
|
||||||
|
return rootChild
|
||||||
|
}
|
||||||
|
|
||||||
// Some GTK 4 X11 frames report screen extents with a 0,0 origin wherever
|
// Some GTK 4 X11 frames report screen extents with a 0,0 origin wherever
|
||||||
// the window really is. Accept such a frame only when both sides name the
|
// the window really is. Accept such a frame only when both sides name the
|
||||||
// same process and the size equals the X11 client
|
// same process and the size equals the X11 client
|
||||||
|
|||||||
@@ -66,6 +66,36 @@ func TestForegroundUnpositionedGTK4Correlation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestForegroundRootChildBoundsCorrelation(t *testing.T) {
|
||||||
|
// GPUI via AccessKit reports frame extents of -1 and gives the frame's
|
||||||
|
// root child window-local bounds at 0,0 with the client's size.
|
||||||
|
client := xorg.Foreground{Known: true, Window: 18874369, PID: 777,
|
||||||
|
X: 262, Y: 184, Width: 500, Height: 400, OuterX: 262, OuterY: 184, OuterWidth: 500, OuterHeight: 400}
|
||||||
|
unbounded := Rectangle{-1, -1, -1, -1}
|
||||||
|
for _, test := range []struct {
|
||||||
|
name string
|
||||||
|
pid int
|
||||||
|
frame Rectangle
|
||||||
|
child Rectangle
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{"unbounded frame, root child at origin", 777, unbounded, Rectangle{0, 0, 500, 400}, true},
|
||||||
|
{"unbounded frame, root child other size", 777, unbounded, Rectangle{0, 0, 468, 368}, false},
|
||||||
|
{"unbounded frame, root child offset origin", 777, unbounded, Rectangle{16, 16, 500, 400}, false},
|
||||||
|
{"unbounded frame, other process", 778, unbounded, Rectangle{0, 0, 500, 400}, false},
|
||||||
|
{"unbounded frame, unbounded child", 777, unbounded, unbounded, false},
|
||||||
|
{"valid matching frame wins over child", 777, Rectangle{262, 184, 500, 400}, Rectangle{0, 0, 10, 10}, true},
|
||||||
|
{"valid nonmatching frame blocks child fallback", 777, Rectangle{0, 0, 300, 200}, Rectangle{0, 0, 500, 400}, false},
|
||||||
|
} {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
bounds := foregroundBounds(test.frame, test.child)
|
||||||
|
if got := foregroundWindowMatches(client, test.pid, bounds); got != test.want {
|
||||||
|
t.Fatalf("match = %v, want %v (bounds %+v)", got, test.want, bounds)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestForegroundWindowCorrelationSteamBigPictureScale(t *testing.T) {
|
func TestForegroundWindowCorrelationSteamBigPictureScale(t *testing.T) {
|
||||||
client := xorg.Foreground{Known: true, Window: 83886130, PID: 111, X: 0, Y: 0, Width: 1920, Height: 1080,
|
client := xorg.Foreground{Known: true, Window: 83886130, PID: 111, X: 0, Y: 0, Width: 1920, Height: 1080,
|
||||||
OuterX: 0, OuterY: 0, OuterWidth: 1920, OuterHeight: 1080}
|
OuterX: 0, OuterY: 0, OuterWidth: 1920, OuterHeight: 1080}
|
||||||
|
|||||||
Reference in new issue
Block a user