diff options
| -rw-r--r-- | modules/bar/components/workspaces/OccupiedBg.qml | 2 | ||||
| -rw-r--r-- | modules/drawers/Drawers.qml | 19 | ||||
| -rw-r--r-- | services/Bluetooth.qml | 9 | ||||
| -rw-r--r-- | services/Brightness.qml | 30 | ||||
| -rw-r--r-- | services/Hyprland.qml | 24 | ||||
| -rw-r--r-- | services/Network.qml | 9 | ||||
| -rw-r--r-- | services/Wallpapers.qml | 24 |
7 files changed, 58 insertions, 59 deletions
diff --git a/modules/bar/components/workspaces/OccupiedBg.qml b/modules/bar/components/workspaces/OccupiedBg.qml index 00f9666..9de3d5b 100644 --- a/modules/bar/components/workspaces/OccupiedBg.qml +++ b/modules/bar/components/workspaces/OccupiedBg.qml @@ -36,7 +36,7 @@ Item { } } if (pills.length > count) - pills.splice(count, pills.length - count); + pills.splice(count, pills.length - count).forEach(p => p.destroy()); } Repeater { diff --git a/modules/drawers/Drawers.qml b/modules/drawers/Drawers.qml index 184d464..d64cb15 100644 --- a/modules/drawers/Drawers.qml +++ b/modules/drawers/Drawers.qml @@ -35,12 +35,7 @@ Variants { height: scope.modelData.height - BorderConfig.thickness * 2 intersection: Intersection.Xor - regions: panels.children.map(c => regionComp.createObject(this, { - x: c.x, - y: c.y, - width: c.width, - height: c.height - })) + regions: regions.instances } anchors.top: true @@ -48,10 +43,18 @@ Variants { anchors.left: true anchors.right: true - Component { - id: regionComp + Variants { + id: regions + + model: panels.children Region { + required property Item modelData + + x: modelData.x + y: modelData.y + width: modelData.width + height: modelData.height intersection: Intersection.Subtract } } diff --git a/services/Bluetooth.qml b/services/Bluetooth.qml index f77001e..43f3636 100644 --- a/services/Bluetooth.qml +++ b/services/Bluetooth.qml @@ -43,12 +43,9 @@ Singleton { const devices = JSON.parse(data).filter(d => d.Name); const rDevices = root.devices; - const len = rDevices.length; - for (let i = 0; i < len; i++) { - const device = rDevices[i]; - if (!devices.find(d => d.Address === device?.address)) - rDevices.splice(i, 1); - } + const destroyed = rDevices.filter(rd => !devices.find(d => d.Address === rd.address)); + for (const device of destroyed) + rDevices.splice(rDevices.indexOf(device), 1).forEach(d => d.destroy()); for (const device of devices) { const match = rDevices.find(d => d.address === device.Address); diff --git a/services/Brightness.qml b/services/Brightness.qml index fabac1f..1687878 100644 --- a/services/Brightness.qml +++ b/services/Brightness.qml @@ -10,24 +10,22 @@ Singleton { id: root property var ddcMonitors: [] - readonly property list<Monitor> monitors: Quickshell.screens.map(screen => monitorComp.createObject(root, { - screen - })) + readonly property list<Monitor> monitors: variants.instances function getMonitorForScreen(screen: ShellScreen): var { - return monitors.find(m => m.screen === screen); + return monitors.find(m => m.modelData === screen); } function increaseBrightness(): void { const focusedName = Hyprland.focusedMonitor.name; - const monitor = monitors.find(m => focusedName === m.screen.name); + const monitor = monitors.find(m => focusedName === m.modelData.name); if (monitor) monitor.setBrightness(monitor.brightness + 0.1); } function decreaseBrightness(): void { const focusedName = Hyprland.focusedMonitor.name; - const monitor = monitors.find(m => focusedName === m.screen.name); + const monitor = monitors.find(m => focusedName === m.modelData.name); if (monitor) monitor.setBrightness(monitor.brightness - 0.1); } @@ -39,6 +37,14 @@ Singleton { ddcProc.running = true; } + Variants { + id: variants + + model: Quickshell.screens + + Monitor {} + } + Process { id: ddcProc @@ -75,9 +81,9 @@ Singleton { component Monitor: QtObject { id: monitor - required property ShellScreen screen - readonly property bool isDdc: root.ddcMonitors.some(m => m.model === screen.model) - readonly property string busNum: root.ddcMonitors.find(m => m.model === screen.model)?.busNum ?? "" + required property ShellScreen modelData + readonly property bool isDdc: root.ddcMonitors.some(m => m.model === modelData.model) + readonly property string busNum: root.ddcMonitors.find(m => m.model === modelData.model)?.busNum ?? "" property real brightness readonly property Process initProc: Process { @@ -109,10 +115,4 @@ Singleton { initProc.running = true; } } - - Component { - id: monitorComp - - Monitor {} - } } diff --git a/services/Hyprland.qml b/services/Hyprland.qml index 515441e..7a2538e 100644 --- a/services/Hyprland.qml +++ b/services/Hyprland.qml @@ -60,12 +60,9 @@ Singleton { const clients = JSON.parse(data); const rClients = root.clients; - const len = rClients.length; - for (let i = 0; i < len; i++) { - const client = rClients[i]; - if (!clients.find(c => c.address === client?.address)) - rClients.splice(i, 1); - } + const destroyed = rClients.filter(rc => !clients.find(c => c.address === rc.address)); + for (const client of destroyed) + rClients.splice(rClients.indexOf(client), 1).forEach(c => c.destroy()); for (const client of clients) { const match = rClients.find(c => c.address === client.address); @@ -88,9 +85,18 @@ Singleton { splitMarker: "" onRead: data => { const client = JSON.parse(data); - root.activeClient = client.address ? clientComp.createObject(root, { - lastIpcObject: client - }) : null; + const rClient = root.activeClient; + if (client.address) { + if (rClient) + rClient.lastIpcObject = client; + else + root.activeClient = clientComp.createObject(root, { + lastIpcObject: client + }); + } else { + rClient.destroy(); + root.activeClient = null; + } } } } diff --git a/services/Network.qml b/services/Network.qml index 3aa1dd6..49d61f8 100644 --- a/services/Network.qml +++ b/services/Network.qml @@ -29,12 +29,9 @@ Singleton { const networks = JSON.parse(data).map(n => [n[0] === "yes", parseInt(n[1]), parseInt(n[2]), n[3]]); const rNetworks = root.networks; - const len = rNetworks.length; - for (let i = 0; i < len; i++) { - const network = rNetworks[i]; - if (!networks.find(n => n[2] === network?.frequency && n[3] === network?.ssid)) - rNetworks.splice(i, 1); - } + const destroyed = rNetworks.filter(rn => !networks.find(n => n[2] === rn.frequency && n[3] === rn.ssid)); + for (const network of destroyed) + rNetworks.splice(rNetworks.indexOf(network), 1).forEach(n => n.destroy()); for (const network of networks) { const match = rNetworks.find(n => n.frequency === network[2] && n.ssid === network[3]); diff --git a/services/Wallpapers.qml b/services/Wallpapers.qml index 1d2a097..4bfa72f 100644 --- a/services/Wallpapers.qml +++ b/services/Wallpapers.qml @@ -12,7 +12,7 @@ Singleton { readonly property string currentNamePath: `${StandardPaths.standardLocations(StandardPaths.GenericStateLocation)[0]}/caelestia/wallpaper/last.txt`.slice(7) readonly property string path: `${StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]}/Wallpapers`.slice(7) - property list<Wallpaper> list + readonly property list<Wallpaper> list: wallpapers.instances property bool showPreview: false readonly property string current: showPreview ? previewPath : actualCurrent property string previewPath @@ -84,23 +84,19 @@ Singleton { command: ["fd", ".", root.path, "-t", "f", "-e", "jpg", "-e", "jpeg", "-e", "png", "-e", "svg"] stdout: SplitParser { splitMarker: "" - onRead: data => { - const list = data.trim().split("\n"); - root.list = list.map(p => wallpaperComp.createObject(root, { - path: p - })); - } + onRead: data => wallpapers.model = data.trim().split("\n") } } - component Wallpaper: QtObject { - required property string path - readonly property string name: path.slice(path.lastIndexOf("/") + 1, path.lastIndexOf(".")) - } - - Component { - id: wallpaperComp + Variants { + id: wallpapers Wallpaper {} } + + component Wallpaper: QtObject { + required property string modelData + readonly property string path: modelData + readonly property string name: path.slice(path.lastIndexOf("/") + 1, path.lastIndexOf(".")) + } } |