chore: apply lsp suggestions and indicator for primary sink

This commit is contained in:
Nydragon 2024-08-29 10:33:28 +02:00
parent 4c9fb99d39
commit 25f7c1ed6c
Signed by: nydragon
SSH key fingerprint: SHA256:iQnIC12spf4QjWSbarmkD2No1cLMlu6TWoV7K6cYF5g
7 changed files with 33 additions and 30 deletions

View file

@ -1,4 +1,4 @@
import "root:base" import "../../base"
import Quickshell.Services.UPower import Quickshell.Services.UPower
import QtQuick import QtQuick
import QtQuick.Layouts import QtQuick.Layouts

View file

@ -1,4 +1,4 @@
import "root:base" import "../../base"
import QtQuick.Layouts import QtQuick.Layouts
BRectangle { BRectangle {

View file

@ -3,7 +3,7 @@ import QtQuick.Layouts
import QtQuick.Controls import QtQuick.Controls
import Quickshell import Quickshell
import Quickshell.Services.SystemTray import Quickshell.Services.SystemTray
import "root:base" import "../../base"
BRectangle { BRectangle {
height: 112 height: 112

View file

@ -4,7 +4,7 @@ import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
Rectangle { Rectangle {
id: elem id: root
required property bool focused required property bool focused
required property int wnum required property int wnum
@ -27,11 +27,11 @@ Rectangle {
hoverEnabled: true hoverEnabled: true
onEntered: () => { onEntered: () => {
elem.hovered = true; root.hovered = true;
} }
onExited: () => { onExited: () => {
elem.hovered = false; root.hovered = false;
} }
onClicked: () => { onClicked: () => {
switcher.running = true; switcher.running = true;
@ -40,14 +40,14 @@ Rectangle {
Process { Process {
id: switcher id: switcher
command: ["swaymsg", "workspace", `${wnum}`] command: ["swaymsg", "workspace", `${root.wnum}`]
} }
states: State { states: State {
name: "focused" name: "focused"
when: active when: root.active
PropertyChanges { PropertyChanges {
target: elem target: root
Layout.rightMargin: activeMargin Layout.rightMargin: activeMargin
Layout.leftMargin: activeMargin Layout.leftMargin: activeMargin
} }

View file

@ -2,33 +2,33 @@ import QtQuick
import Quickshell.Io import Quickshell.Io
Item { Item {
id: root
property int active: 1 // currently active workspace property int active: 1 // currently active workspace
property int amount: 10 // amount of workspaces property int amount: 10 // amount of workspaces
property string name: "" // name of the current desktop property string name: "" // name of the current desktop
Process { Process {
property string name: ""
command: ["env"] command: ["env"]
running: true running: true
stdout: SplitParser { stdout: SplitParser {
onRead: data => { onRead: data => {
if (data.startsWith("XDG_CURRENT_DESKTOP=")) if (data.startsWith("XDG_CURRENT_DESKTOP="))
name = data.slice(20); root.name = data.slice(20);
} }
} }
} }
Process { Process {
command: ["swaymsg", "-mtsubscribe", "[\"workspace\"]"] command: ["swaymsg", "-mtsubscribe", "[\"workspace\"]"]
running: name === "sway" running: root.name === "sway"
stdout: SplitParser { stdout: SplitParser {
onRead: data => { onRead: data => {
const parsed = JSON.parse(data); const parsed = JSON.parse(data);
if (parsed.change == "focus") { if (parsed.change == "focus") {
active = parsed.current.num; root.active = parsed.current.num;
} }
} }
} }

View file

@ -1,10 +1,11 @@
import Quickshell pragma ComponentBehavior: Bound
import QtQuick import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import Quickshell.Io // for Process import "../../base"
import "root:base"
BRectangle { BRectangle {
id: root
height: 100 + layout.spacing * (workspace.amount - 1) height: 100 + layout.spacing * (workspace.amount - 1)
WorkspaceIPC { WorkspaceIPC {

View file

@ -2,20 +2,20 @@ import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Controls import QtQuick.Controls
import Quickshell.Services.Pipewire import Quickshell.Services.Pipewire
import Quickshell
RowLayout { RowLayout {
id: root
required property PwNode node required property PwNode node
// bind the node so we can read its properties // bind the node so we can read its properties
PwObjectTracker { PwObjectTracker {
objects: [node] objects: [root.node]
} }
Image { Image {
source: { source: {
const getFallback = () => node.isStream ? "root:/../assets/folder-music.svg" : "root:/../assets/audio-volume-high.svg"; const getFallback = () => node.isStream ? "root:/../assets/folder-music.svg" : "root:/../assets/audio-volume-high.svg";
node.properties["application.icon-name"] ? `image://icon/${node.properties["application.icon-name"]}` : getFallback(); root.node.properties["application.icon-name"] ? `image://icon/${root.node.properties["application.icon-name"]}` : getFallback();
} }
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
@ -37,8 +37,8 @@ RowLayout {
Label { Label {
id: name id: name
text: { text: {
const app = node.isStream ? `[${node.properties["application.name"]}] ` : ""; const app = root.node.isStream ? `[${root.node.properties["application.name"]}] ` : "";
return app + (node.properties["media.name"] ?? node.description); return app + (root.node.properties["media.name"] ?? root.node.description);
} }
// Cede space to other elements -> don't have stupidly long names detroying the layout // Cede space to other elements -> don't have stupidly long names detroying the layout
Layout.maximumWidth: 0 Layout.maximumWidth: 0
@ -50,7 +50,7 @@ RowLayout {
} }
Button { Button {
visible: node.isSink visible: root.node.isSink
width: 10 width: 10
checkable: true checkable: true
Image { Image {
@ -61,25 +61,27 @@ RowLayout {
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
} }
onClicked: node.audio.muted = !node.audio.muted onClicked: root.node.audio.muted = !root.node.audio.muted
} }
Button { Button {
// TODO: setting a default sink is not implemented yet in QS property bool isDefault: root.node.id === Pipewire.defaultAudioSink.id
visible: node.isSink checked: isDefault
text: "default" checkable: false
visible: root.node.isSink
text: isDefault ? "default" : "not default"
} }
} }
RowLayout { RowLayout {
Label { Label {
Layout.preferredWidth: 50 Layout.preferredWidth: 50
text: `${Math.floor(node.audio.volume * 100)}%` text: `${Math.floor(root.node.audio.volume * 100)}%`
} }
Slider { Slider {
Layout.fillWidth: true Layout.fillWidth: true
value: node.audio.volume value: root.node.audio.volume
onValueChanged: node.audio.volume = value onValueChanged: root.node.audio.volume = value
} }
} }
} }