add app icon to active window, fix app icon method in dock

This commit is contained in:
Kainoa Kanter 2025-08-19 19:04:38 -07:00
parent bc27e237c9
commit 604321e30e
No known key found for this signature in database
GPG key ID: 8703CACD01000000
2 changed files with 25 additions and 14 deletions

View file

@ -2,6 +2,7 @@ import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
import Quickshell import Quickshell
import Quickshell.Widgets
import qs.Commons import qs.Commons
import qs.Services import qs.Services
import qs.Widgets import qs.Widgets
@ -43,6 +44,15 @@ Row {
return focusedWindow ? (focusedWindow.title || focusedWindow.appId || "") : "" return focusedWindow ? (focusedWindow.title || focusedWindow.appId || "") : ""
} }
function getAppIcon() {
const focusedWindow = CompositorService.getFocusedWindow();
if (!focusedWindow || !focusedWindow.appId)
return "";
let icon = Quickshell.iconPath(DesktopEntries.byId(focusedWindow.appId).icon);
return icon || "";
}
// A hidden text element to safely measure the full title width // A hidden text element to safely measure the full title width
NText { NText {
id: fullTitleMetrics id: fullTitleMetrics
@ -72,13 +82,20 @@ Row {
spacing: Style.marginXS * scaling spacing: Style.marginXS * scaling
// Window icon // Window icon
NIcon { Item {
id: windowIcon width: Style.fontSizeL * scaling * 1.2
text: "dialogs" height: Style.fontSizeL * scaling * 1.2
font.pointSize: Style.fontSizeL * scaling anchors.verticalCenter: parent.verticalCenter
verticalAlignment: Text.AlignVCenter visible: getTitle() !== ""
anchors.verticalCenter: parent.verticalCenter
visible: getTitle() !== "" IconImage {
id: windowIcon
anchors.fill: parent
source: getAppIcon()
asynchronous: true
smooth: true
visible: source !== ""
}
} }
NText { NText {

View file

@ -159,13 +159,7 @@ NLoader {
function getAppIcon(toplevel: Toplevel): string { function getAppIcon(toplevel: Toplevel): string {
if (!toplevel) if (!toplevel)
return "" return ""
let icon = Quickshell.iconPath(toplevel.appId?.toLowerCase(), true) let icon = Quickshell.iconPath(DesktopEntries.byId(toplevel.appId?.toLowerCase()).icon);
if (!icon)
icon = Quickshell.iconPath(toplevel.appId, true)
if (!icon)
icon = Quickshell.iconPath(toplevel.title?.toLowerCase(), true)
if (!icon)
icon = Quickshell.iconPath(toplevel.title, true)
return icon || Quickshell.iconPath("application-x-executable", true) return icon || Quickshell.iconPath("application-x-executable", true)
} }