asmvik / asmvik/yabai

Yabai query cache gives empty title on discarded Chrome windows

Open
#2,798 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
29.6k
Forks
758
PR merge metrics
No merged PRs in 30d

Description

@asmvik
I just found that the fix that you introduced below (caching of queries) creates a problem with Chrome title [https://github.com/asmvik/yabai/commit/0e3e999de1b51af0aa1eccd379b857402aa39d68](https://github.com/asmvik/yabai/commit/0e3e999de1b51af0aa1eccd379b857402aa39d68)

Chrome discards "windows" to save memory.
When this happens, yabai gets the`window_title_changed` signal and stores "" (empty string) as window title, and this title is cached forever.
Even when you wake the window by focusing it manually the empty title stays the same forever.
You either have to manually rename the window (with name window feature in chrome) or do `yabai --restart-service`
You can try to reproduce it by going to `chrome://discards/` in Chrome and triggering "discard" on a window (sometimes you have to click few times and wait)

`yabai -m query --windows id,app,title`
gives this
```
},{
"id":362,
"app":"Google Chrome",
"title":""
},{
```
but direct AX Query Script like the one below
```
import Foundation
import ApplicationServices

let pid: pid_t = 1123 // replace with Chrome's PID
let app = AXUIElementCreateApplication(pid)

var windowsRef: CFTypeRef?
AXUIElementCopyAttributeValue(app, kAXWindowsAttribute as CFString, &windowsRef)

if let windowList = windowsRef as? [AXUIElement] {
for (index, window) in windowList.enumerated() {
var titleRef: CFTypeRef?
let result = AXUIElementCopyAttributeValue(window, kAXTitleAttribute as CFString, &titleRef)
let title = (titleRef as? String) ?? ""
print("[\(index)] result=\(result.rawValue) title='\(title)'")
}
}
```
gives this
```
},{
"id":362,
"app":"Google Chrome",
"title":"vanillia-result - Google Chrome – vanillia"
},{
```

I don't actually know how to fix it as this is lifetime issue.
Perhaps you can do actual query when you get "empty title" to refresh the cache?
I'm not sure if other apps are affected, but it's possible that all Chromium based apps will have same problem (assuming that window discarding is enabled).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the query cache and the window_title_changed signal handling, then reproduce the issue through Chrome's chrome://discards/ page and compare yabai's cached result with the direct AX query shown in the report. Done means discarded Chrome windows regain their title after being woken, without requiring a service restart or manual rename.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, macos
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
43/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.