ActiveWindow: fix hyprland icon display (fixes #201)
This commit is contained in:
parent
977b2d9e7c
commit
0aaf78fc51
1 changed files with 24 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Quickshell
|
import Quickshell
|
||||||
|
import Quickshell.Wayland
|
||||||
import Quickshell.Widgets
|
import Quickshell.Widgets
|
||||||
import qs.Commons
|
import qs.Commons
|
||||||
import qs.Services
|
import qs.Services
|
||||||
|
|
@ -9,28 +10,34 @@ import qs.Widgets
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property ShellScreen screen
|
property ShellScreen screen
|
||||||
property real scaling: 1.0
|
property real scaling: 1.0
|
||||||
readonly property real minWidth: 160
|
readonly property real minWidth: 160
|
||||||
readonly property real maxWidth: 400
|
readonly property real maxWidth: 400
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
spacing: Style.marginS * scaling
|
spacing: Style.marginS * scaling
|
||||||
visible: getTitle() !== ""
|
visible: getTitle() !== ""
|
||||||
|
|
||||||
function getTitle() {
|
function getTitle() {
|
||||||
// Use the service's focusedWindowTitle property which is updated immediately
|
|
||||||
// when WindowOpenedOrChanged events are received
|
|
||||||
return CompositorService.focusedWindowTitle !== "(No active window)" ? CompositorService.focusedWindowTitle : ""
|
return CompositorService.focusedWindowTitle !== "(No active window)" ? CompositorService.focusedWindowTitle : ""
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAppIcon() {
|
function getAppIcon() {
|
||||||
|
// Try CompositorService first
|
||||||
const focusedWindow = CompositorService.getFocusedWindow()
|
const focusedWindow = CompositorService.getFocusedWindow()
|
||||||
if (!focusedWindow || !focusedWindow.appId)
|
if (focusedWindow && focusedWindow.appId) {
|
||||||
return ""
|
return Icons.iconForAppId(focusedWindow.appId.toLowerCase())
|
||||||
|
}
|
||||||
|
|
||||||
return Icons.iconForAppId(focusedWindow.appId)
|
// Fallback to ToplevelManager
|
||||||
|
if (ToplevelManager && ToplevelManager.activeToplevel) {
|
||||||
|
const activeToplevel = ToplevelManager.activeToplevel
|
||||||
|
if (activeToplevel.appId) {
|
||||||
|
return Icons.iconForAppId(activeToplevel.appId.toLowerCase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// A hidden text element to safely measure the full title width
|
// A hidden text element to safely measure the full title width
|
||||||
|
|
@ -81,8 +88,6 @@ RowLayout {
|
||||||
|
|
||||||
NText {
|
NText {
|
||||||
id: titleText
|
id: titleText
|
||||||
|
|
||||||
// For short titles, show full. For long titles, truncate and expand on hover
|
|
||||||
Layout.preferredWidth: {
|
Layout.preferredWidth: {
|
||||||
if (mouseArea.containsMouse) {
|
if (mouseArea.containsMouse) {
|
||||||
return Math.round(Math.min(fullTitleMetrics.contentWidth, root.maxWidth * scaling))
|
return Math.round(Math.min(fullTitleMetrics.contentWidth, root.maxWidth * scaling))
|
||||||
|
|
@ -91,7 +96,6 @@ RowLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
|
|
||||||
horizontalAlignment: Text.AlignLeft
|
horizontalAlignment: Text.AlignLeft
|
||||||
text: getTitle()
|
text: getTitle()
|
||||||
font.pointSize: Style.fontSizeS * scaling
|
font.pointSize: Style.fontSizeS * scaling
|
||||||
|
|
@ -119,4 +123,14 @@ RowLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: CompositorService
|
||||||
|
function onActiveWindowChanged() {
|
||||||
|
windowIcon.source = Qt.binding(getAppIcon)
|
||||||
|
}
|
||||||
|
function onWindowListChanged() {
|
||||||
|
windowIcon.source = Qt.binding(getAppIcon)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue