package atspi import "github.com/bnema/neferwl/internal/ports" // AT-SPI constants (atspi-constants.h). The role ids are the AtspiRole enum // values; the state ids are bit indices of the state set. const ( roleCheckBox = 7 roleComboBox = 11 roleDialog = 16 roleFrame = 23 roleMenuItem = 35 rolePageTab = 37 rolePushButton = 43 roleRadioButton = 44 roleToggleButton = 62 roleWindow = 69 roleLink = 88 roleDocumentFrame = 82 roleDocumentWeb = 95 stateActive = 1 stateShowing = 25 stateVisible = 30 roleWords = 5 // int32 words of a role set in a MatchRule stateWords = 2 // int32 words of a state set in a MatchRule // AtspiCollectionMatchType and AtspiCollectionSortOrder values. matchAll = 1 matchAny = 2 sortCanonical = 1 matchCount = 500 maxDepth = 30 maxWalkNodes = 3000 maxFrames = 32 sizeTolerance = 40 maxMatchesRead = matchCount ) // clickableRoles are the roles that become hint targets. var clickableRoles = []uint32{ roleLink, rolePushButton, roleToggleButton, roleCheckBox, roleRadioButton, roleMenuItem, rolePageTab, roleComboBox, } // matchRule is the Collection query: showing and visible objects of the // clickable roles (only links when linksOnly), plus web documents for coverage. type matchRule struct{ linksOnly bool } func (r matchRule) roles() []uint32 { if r.linksOnly { return []uint32{roleLink, roleDocumentFrame, roleDocumentWeb} } return append(append([]uint32(nil), clickableRoles...), roleDocumentFrame, roleDocumentWeb) } // roleBits packs role ids into the bit set of a MatchRule: bit id%32 of word // id/32. func roleBits(ids []uint32) []int32 { words := make([]int32, roleWords) for _, id := range ids { if w := int(id / 32); w < len(words) { words[w] |= int32(uint32(1) << (id % 32)) } } return words } // stateBits packs state ids into the bit set of a MatchRule. func stateBits(ids ...uint32) []int32 { words := make([]int32, stateWords) for _, id := range ids { if w := int(id / 32); w < len(words) { words[w] |= int32(uint32(1) << (id % 32)) } } return words } func hasState(set uint64, state uint) bool { return set&(1<