Files
TNCcat/qml/OverlayWindow.qml
JulianandClaude Opus 5 0aceb3665d Fix the collapsed cat window on Linux, warn about the compositor
The CatDefs singleton did not resolve on the reporter's Linux build, which
showed up as "property mood of object CatDefs is not a function". The same
lookup failure made CatDefs.aspect undefined, so the cat window's height became
NaN and the cat rendered as a moving line. The mug survived because its height
used a literal ratio.

The singleton is gone rather than repaired, since nothing in it had to be
shared. The mood name now comes from C++, derived from the enum key, so there
is one source of truth instead of a list in QML that had to match. Window sizes
now follow the implicit size of the drawing they contain, so the proportions
live in the one file that defines them.

Also for X11: TNCat now warns, naming Xfce's compositor setting, when its
window comes up without an alpha channel, which is what a missing compositor
looks like and why the mug had a black background. Opaque mode no longer hides
the chip and the mug. TNCAT_DEBUG=1 logs window geometry.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 09:33:44 +02:00

131 lines
4.0 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import TNCat
// One screen-filling, click-through window that holds the cat and the chip.
// Wayland does not let a client place its own window, so there the cat moves
// inside this overlay instead of the window moving across the desktop.
Window {
id: win
required property CatController cat
required property AppSettings settings
signal settingsRequested()
// Fullscreen is a visibility, not a visible flag, so the mode switch has to
// go through visibility or the two fight each other.
property bool overlayActive: false
readonly property int catW: settings.catSize
readonly property int catH: Math.round(catW * sprite.implicitHeight / sprite.implicitWidth)
readonly property real groundY: height - catH - settings.bottomMargin
// Only the cat itself should swallow clicks; everything else falls through.
function refreshInputRegion() {
Platform.setInputRegion(win, Qt.rect(Math.round(cat.x), Math.round(groundY), catW, catH))
}
visibility: overlayActive ? Window.FullScreen : Window.Hidden
color: "transparent"
flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Tool
| Qt.NoDropShadowWindowHint | Qt.WindowDoesNotAcceptFocus
title: qsTr("TNCat")
onOverlayActiveChanged: {
if (!overlayActive)
return
cat.stageWidth = width
cat.catWidth = catW
refreshInputRegion()
}
onWidthChanged: cat.stageWidth = width
onCatWChanged: cat.catWidth = catW
Binding {
target: win.cat
property: "catCenter"
value: Qt.point(win.x + win.cat.x + win.catW / 2, win.y + win.groundY + win.catH / 2)
}
// Coalesce mask updates: one X11 round trip per frame of walking is plenty.
Timer {
interval: 33
running: win.overlayActive
repeat: true
onTriggered: win.refreshInputRegion()
}
Chip {
id: curl
x: win.cat.chipX - width / 2
y: win.height - height - win.settings.bottomMargin
width: Math.round(win.settings.catSize * 0.46)
height: Math.round(width * curl.implicitHeight / curl.implicitWidth)
visible: win.cat.chipVisible
spin: win.cat.chipSpin
Behavior on x {
NumberAnimation { duration: 320; easing.type: Easing.OutQuad }
}
}
Cup {
id: mug
x: win.cat.cupX - width / 2
y: win.height - height - win.settings.bottomMargin
width: Math.round(win.settings.catSize * 0.38)
height: Math.round(width * mug.implicitHeight / mug.implicitWidth)
visible: win.cat.cupVisible
}
Item {
id: catItem
x: win.cat.x
y: win.groundY
width: win.catW
height: win.catH
Cat {
id: sprite
anchors.fill: parent
coat: win.settings.coat
facingRight: win.cat.facingRight
mood: win.cat.moodName
lifted: win.cat.dragging
petted: win.cat.hovered && !win.cat.dragging
look: win.cat.look
showCodes: win.settings.showCodes
Accessible.role: Accessible.Button
Accessible.name: qsTr("TNCat")
}
HoverHandler {
onHoveredChanged: win.cat.hovered = hovered
}
DragHandler {
target: null
onActiveChanged: win.cat.dragging = active
onCentroidChanged: {
if (active)
win.cat.x = Math.max(0, Math.min(win.cat.stageWidth - win.catW,
catItem.x + centroid.position.x - centroid.pressPosition.x))
}
}
TapHandler {
acceptedButtons: Qt.LeftButton
onTapped: win.cat.pet()
onDoubleTapped: win.settingsRequested()
onLongPressed: win.settingsRequested()
}
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: win.settingsRequested()
}
}
}