Improved ActiveWindow
This commit is contained in:
parent
4fcdb1543d
commit
fbfda31733
1 changed files with 31 additions and 72 deletions
|
|
@ -22,7 +22,7 @@ Row {
|
||||||
repeat: false
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
showingFullTitle = false
|
showingFullTitle = false
|
||||||
titleText.text = getDisplayText()
|
// No need to update text here, the width property change will handle it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,13 +36,34 @@ Row {
|
||||||
showingFullTitle = true
|
showingFullTitle = true
|
||||||
fullTitleTimer.restart()
|
fullTitleTimer.restart()
|
||||||
}
|
}
|
||||||
titleText.text = getDisplayText()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFocusedWindow() {
|
||||||
|
if (typeof NiriService === "undefined" || NiriService.focusedWindowIndex < 0
|
||||||
|
|| NiriService.focusedWindowIndex >= NiriService.windows.length) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return NiriService.windows[NiriService.focusedWindowIndex]
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTitle() {
|
||||||
|
const focusedWindow = getFocusedWindow()
|
||||||
|
return focusedWindow ? (focusedWindow.title || focusedWindow.appId || "") : ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// A hidden text element to safely measure the full title width
|
||||||
|
NText {
|
||||||
|
id: fullTitleMetrics
|
||||||
|
visible: false
|
||||||
|
text: getTitle()
|
||||||
|
font: titleText.font
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: row.width + Style.marginSmall * scaling * 2
|
// Let the Rectangle size itself based on its content (the Row)
|
||||||
height: row.height
|
width: row.width + Style.marginMedium* scaling * 2
|
||||||
|
height: row.height + Style.marginSmall * scaling
|
||||||
color: Color.mSurfaceVariant
|
color: Color.mSurfaceVariant
|
||||||
radius: Style.radiusSmall * scaling
|
radius: Style.radiusSmall * scaling
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
@ -66,19 +87,20 @@ Row {
|
||||||
font.pointSize: Style.fontSizeLarge * scaling
|
font.pointSize: Style.fontSizeLarge * scaling
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
visible: getDisplayText() !== ""
|
visible: getTitle() !== ""
|
||||||
}
|
}
|
||||||
|
|
||||||
NText {
|
NText {
|
||||||
id: titleText
|
id: titleText
|
||||||
width: (showingFullTitle || mouseArea.containsMouse) ? 300 * scaling : 100 * scaling
|
width: (showingFullTitle || mouseArea.containsMouse) ? fullTitleMetrics.contentWidth : 150 * scaling
|
||||||
text: getDisplayText()
|
text: getTitle()
|
||||||
font.pointSize: Style.fontSizeReduced * scaling
|
font.pointSize: Style.fontSizeReduced * scaling
|
||||||
font.weight: Style.fontWeightBold
|
font.weight: Style.fontWeightBold
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
color: Color.mTertiary
|
color: Color.mTertiary
|
||||||
|
|
||||||
Behavior on width {
|
Behavior on width {
|
||||||
NumberAnimation {
|
NumberAnimation {
|
||||||
duration: Style.animationSlow
|
duration: Style.animationSlow
|
||||||
|
|
@ -87,77 +109,14 @@ Row {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mouse area for hover detection
|
// Mouse area for hover detection
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: mouseArea
|
id: mouseArea
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: Qt.IBeamCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onEntered: {
|
|
||||||
titleText.text = getDisplayText()
|
|
||||||
}
|
|
||||||
onExited: {
|
|
||||||
titleText.text = getDisplayText()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getDisplayText() {
|
|
||||||
// Check if Niri service is available
|
|
||||||
if (typeof NiriService === "undefined") {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the focused window data
|
|
||||||
const focusedWindow = NiriService.focusedWindowIndex >= 0 && NiriService.focusedWindowIndex
|
|
||||||
< NiriService.windows.length ? NiriService.windows[NiriService.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 title
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isGenericName(programName)) {
|
|
||||||
return title
|
|
||||||
}
|
|
||||||
|
|
||||||
return programName
|
|
||||||
}
|
|
||||||
|
|
||||||
return title
|
|
||||||
|
|
||||||
// // Use appId for program name, show full title on hover or window switch
|
|
||||||
// if (showingFullTitle || mouseArea.containsMouse) {
|
|
||||||
// return truncateTitle(title || appId, 50)
|
|
||||||
// } else {
|
|
||||||
// return truncateTitle(title || appId, 20)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
function truncateTitle(title, length) {
|
|
||||||
if (title.length > length) {
|
|
||||||
return title.substring(0, length - 3) + "..."
|
|
||||||
}
|
|
||||||
return title
|
|
||||||
}
|
|
||||||
|
|
||||||
function isGenericName(name) {
|
|
||||||
const genericNames = ["window", "application", "app", "program", "process", "unknown"]
|
|
||||||
return genericNames.includes(name.toLowerCase())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue