Files
cthulhu/internal/app/wine_window_titles.go

63 lines
1.9 KiB
Go

// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package app
import "git.stormux.org/storm/cthulhu/internal/atspi"
type wineWindowTitle struct {
text string
foreground atspi.ForegroundTitle
}
// Wine control output stays in its presenter. Its titles use the same
// event-loop policy as native title changes, through a copied-data mailbox.
func connectWineWindowTitles(owner *wineEventPresenter, live *liveSettings, adapter Adapter) {
if live == nil {
return
}
live.wineTitles = make(chan wineWindowTitle, 1)
source, _ := adapter.(windowTitleSource)
owner.windowTitle = func(text string) {
update := wineWindowTitle{text: text}
if source != nil {
update.foreground = source.ForegroundTitle()
}
select {
case <-live.wineTitles:
default:
}
select {
case live.wineTitles <- update:
default:
}
}
}
func (titles *windowTitleController) wineChanged(update wineWindowTitle) {
native := update.foreground.Title
// A helper may deliver a delayed focus after another program took the
// foreground. X11 metadata is authoritative when it is available.
if native.Window != 0 && !equivalentWindowTitles(native.Title, update.text) {
return
}
if titles.foreground != nil {
current := titles.foreground.Foreground()
if current.Client.Known && current.Client.Window == 0 {
return
}
}
changed := titles.lastTitle != ""
if titles.pending != nil {
changed = titles.pending.changed
}
if native.Window != 0 && (update.foreground.Epoch != titles.lastNative.Epoch ||
native.Window != titles.lastNative.Title.Window || native.TitleWindow != titles.lastNative.Title.TitleWindow) {
changed = false
}
titles.queue(pendingWindowTitle{text: update.text, native: native,
window: titles.state.owner.window, epoch: update.foreground.Epoch, changed: changed,
application: titles.application})
}