// Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // SPDX-License-Identifier: GPL-3.0-or-later package atspi import ( "git.stormux.org/storm/cthulhu/internal/platform/xorg" "testing" ) func TestForegroundWindowCorrelation(t *testing.T) { client := xorg.Foreground{Known: true, Window: 45, PID: 123, X: 10, Y: 30, Width: 400, Height: 300, OuterX: 8, OuterY: 5, OuterWidth: 404, OuterHeight: 327} for _, test := range []struct { name string pid int bounds Rectangle want bool }{ {"client", 123, Rectangle{10, 30, 400, 300}, true}, {"decorated", 123, Rectangle{8, 5, 404, 327}, true}, {"other process", 124, Rectangle{10, 30, 400, 300}, false}, {"same process other window", 123, Rectangle{420, 30, 400, 300}, false}, {"same process scaled window", 123, Rectangle{10, 30, 200, 150}, true}, {"scaled window shifted", 123, Rectangle{11, 30, 200, 150}, false}, {"scaled window wrong aspect", 123, Rectangle{10, 30, 200, 120}, false}, {"scaled window too small", 123, Rectangle{10, 30, 100, 75}, false}, {"other process scaled window", 124, Rectangle{10, 30, 200, 150}, false}, {"dialog", 123, Rectangle{40, 50, 200, 100}, false}, {"missing bounds", 123, Rectangle{}, false}, } { t.Run(test.name, func(t *testing.T) { if got := foregroundWindowMatches(client, test.pid, test.bounds); got != test.want { t.Fatalf("match = %v, want %v", got, test.want) } }) } } func TestForegroundWindowCorrelationSteamBigPictureScale(t *testing.T) { 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} if !foregroundWindowMatches(client, 111, Rectangle{X: 0, Y: 0, Width: 1353, Height: 761}) { t.Fatal("same-process logical-pixel frame did not match X11 foreground") } } func TestForegroundMenuPopupCorrelation(t *testing.T) { client := xorg.Foreground{Known: true, Window: 45, PID: 123} main := NewObjectID(":1.40", "/main") popup := NewObjectID(":1.40", "/popup") for _, test := range []struct { name string client xorg.Foreground main ObjectID popup ObjectID pid int menu bool want bool }{ {"active menu in foreground application", client, main, popup, 123, true, true}, {"inactive menu", client, main, popup, 123, false, false}, {"other application", client, main, NewObjectID(":1.41", "/popup"), 123, true, false}, {"other process", client, main, popup, 124, true, false}, {"ordinary sibling window", client, main, popup, 123, false, false}, {"no foreground client", xorg.Foreground{Known: true}, main, popup, 123, true, false}, {"no owned main window", client, ObjectID{}, popup, 123, true, false}, } { t.Run(test.name, func(t *testing.T) { if got := foregroundMenuPopupMatches(test.client, test.main, test.popup, test.pid, test.menu); got != test.want { t.Fatalf("match = %v, want %v", got, test.want) } }) } }