Formatting

This commit is contained in:
quadbyte 2025-08-15 17:20:24 -04:00
parent 1d7d0752ad
commit c0cfdff1d9
3 changed files with 109 additions and 104 deletions

View file

@ -9,10 +9,10 @@ Row {
anchors.verticalCenter: parent.verticalCenter
spacing: Style.marginSmall * scaling
visible: Settings.data.bar.showActiveWindow
property bool showingFullTitle: false
property int lastWindowIndex: -1
// Timer to hide full title after window switch
Timer {
id: fullTitleTimer
@ -23,7 +23,7 @@ Row {
titleText.text = getDisplayText()
}
}
// Update text when window changes
Connections {
target: typeof Niri !== "undefined" ? Niri : null
@ -37,7 +37,7 @@ Row {
titleText.text = getDisplayText()
}
}
// Window icon
NText {
id: windowIcon
@ -49,21 +49,21 @@ Row {
color: Colors.mPrimary
visible: getDisplayText() !== ""
}
// Window title container
Item {
id: titleContainer
width: titleText.width
height: titleText.height
anchors.verticalCenter: parent.verticalCenter
Behavior on width {
NumberAnimation {
duration: 300
easing.type: Easing.OutCubic
}
}
NText {
id: titleText
text: getDisplayText()
@ -73,79 +73,76 @@ Row {
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
// Mouse area for hover detection
MouseArea {
id: titleContainerMouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.IBeamCursor
onEntered: {
titleText.text = getDisplayText()
}
onExited: {
titleText.text = getDisplayText()
}
}
}
// Mouse area for hover detection
MouseArea {
id: titleContainerMouseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.IBeamCursor
onEntered: {
titleText.text = getDisplayText()
}
onExited: {
titleText.text = getDisplayText()
}
}
}
function getDisplayText() {
// Check if Niri service is available
if (typeof Niri === "undefined") {
return ""
}
// Get the focused window data
const focusedWindow = Niri.focusedWindowIndex >= 0 && Niri.focusedWindowIndex < Niri.windows.length
? Niri.windows[Niri.focusedWindowIndex]
: null
const focusedWindow = Niri.focusedWindowIndex >= 0
&& Niri.focusedWindowIndex < Niri.windows.length ? Niri.windows[Niri.focusedWindowIndex] : null
if (!focusedWindow) {
return ""
}
const appId = focusedWindow.appId || ""
const title = focusedWindow.title || ""
// If no appId, fall back to title processing
if (!appId) {
if (!title || title === "(No active window)" || title === "(Unnamed window)") {
return ""
}
// Extract program name from title (before first space or special characters)
const programName = title.split(/[\s\-_]/)[0]
if (programName.length <= 2 || programName === title) {
return truncateTitle(title)
}
if (showingFullTitle || titleContainerMouseArea.containsMouse || isGenericName(programName)) {
return truncateTitle(title)
}
return programName
}
// Use appId for program name, show full title on hover or window switch
if (showingFullTitle || titleContainerMouseArea.containsMouse) {
return truncateTitle(title || appId)
}
return appId
}
function truncateTitle(title) {
if (title.length > 50) {
return title.substring(0, 47) + "..."
}
return title
}
function isGenericName(name) {
const genericNames = ["window", "application", "app", "program", "process", "unknown"]
return genericNames.includes(name.toLowerCase())
}
}
}