bar: fix activewindow

This commit is contained in:
2 * r + 2 * t 2025-04-29 23:45:12 +10:00
parent e0f01ccdb9
commit 2fd1e90d57
3 changed files with 24 additions and 22 deletions

View file

@ -15,7 +15,7 @@ StyledRect {
MaterialIcon {
id: icon
text: Icons.getAppCategoryIcon(Hyprland.activeClient?.class) ?? "desktop_windows"
text: Icons.getAppCategoryIcon(Hyprland.activeClient?.wmClass, "desktop_windows")
color: root.colour
}

View file

@ -11,7 +11,7 @@ Singleton {
property list<Client> clients: []
readonly property var workspaces: Hyprland.workspaces
readonly property var monitors: Hyprland.monitors
readonly property Client activeClient: Client {}
property Client activeClient: null
readonly property HyprlandWorkspace activeWorkspace: focusedMonitor?.activeWorkspace ?? null
readonly property HyprlandMonitor focusedMonitor: Hyprland.monitors.values.find(m => m.lastIpcObject.focused) ?? null
@ -54,25 +54,30 @@ Singleton {
id: getActiveClient
command: ["sh", "-c", "hyprctl -j activewindow | jq -c"]
stdout: SplitParser {
onRead: data => root.activeClient.lastIpcObject = JSON.parse(data)
onRead: data => {
const client = JSON.parse(data);
root.activeClient = client.address ? clientComp.createObject(root, {
lastIpcObject: client
}) : null;
}
}
}
component Client: QtObject {
property var lastIpcObject
property string address: lastIpcObject?.address ?? ""
property string wmClass: lastIpcObject?.class ?? ""
property string title: lastIpcObject?.title ?? ""
property string initialClass: lastIpcObject?.initialClass ?? ""
property string initialTitle: lastIpcObject?.initialTitle ?? ""
property int x: (lastIpcObject?.at ?? [])[0] ?? 0
property int y: (lastIpcObject?.at ?? [])[1] ?? 0
property int width: (lastIpcObject?.size ?? [])[0] ?? 0
property int height: (lastIpcObject?.size ?? [])[1] ?? 0
property HyprlandWorkspace workspace: Hyprland.workspaces.values.find(w => w.id === lastIpcObject?.workspace?.id) ?? null
property bool floating: lastIpcObject?.floating ?? false
property bool fullscreen: lastIpcObject?.fullscreen ?? false
property int pid: lastIpcObject?.pid ?? 0
required property var lastIpcObject
property string address: lastIpcObject.address
property string wmClass: lastIpcObject.class
property string title: lastIpcObject.title
property string initialClass: lastIpcObject.initialClass
property string initialTitle: lastIpcObject.initialTitle
property int x: lastIpcObject.at[0]
property int y: lastIpcObject.at[1]
property int width: lastIpcObject.size[0]
property int height: lastIpcObject.size[1]
property HyprlandWorkspace workspace: Hyprland.workspaces.values.find(w => w.id === lastIpcObject.workspace.id) ?? null
property bool floating: lastIpcObject.floating
property bool fullscreen: lastIpcObject.fullscreen
property int pid: lastIpcObject.pid
}
Component {

View file

@ -152,17 +152,14 @@ Singleton {
property string osIcon: ""
function getAppCategoryIcon(name: string): string {
if (!name)
return null;
function getAppCategoryIcon(name: string, fallback: string): string {
const categories = DesktopEntries.applications.values.find(app => app.id === name)?.categories;
if (categories)
for (const [key, value] of Object.entries(this.categoryIcons))
if (categories.includes(key))
return value;
return "terminal";
return fallback;
}
function getNetworkIcon(strength: int): string {