Compare commits
91
Commits
v0.4.0
...
module/wifi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74261f0a49 | ||
|
|
eb65e44ac8 | ||
|
|
e76350fa7f | ||
|
|
de44096132 | ||
|
|
59213cf30d | ||
|
|
8ec454306f | ||
|
|
015c1fb27d | ||
|
|
968055a24e | ||
|
|
f6cb7e44c2 | ||
|
|
5a8939bc1e | ||
|
|
46855b6a7f | ||
|
|
dfc203f905 | ||
|
|
78c0a6fdfc | ||
|
|
98fc9aa97a | ||
|
|
db76ae7dc6 | ||
|
|
de55b5f1e4 | ||
|
|
2c62ad093c | ||
|
|
97c48d03f4 | ||
|
|
69d8f6d727 | ||
|
|
ddfa6cd3c4 | ||
|
|
c35e73886a | ||
|
|
c7bf7cdc0b | ||
|
|
177b0f319c | ||
|
|
d3e781731e | ||
|
|
abb180c947 | ||
|
|
babfe4b3de | ||
|
|
31f73b05e4 | ||
|
|
a6c1985bff | ||
|
|
69c2bfae9d | ||
|
|
6071223009 | ||
|
|
43647dd486 | ||
|
|
43f070f887 | ||
|
|
4e75f21446 | ||
|
|
654632128f | ||
|
|
797fe31b2b | ||
|
|
4037a1dd0f | ||
|
|
03ef51cd0c | ||
|
|
a41c0adb3e | ||
|
|
33c9432390 | ||
|
|
bfaba488f3 | ||
|
|
0c788ca4dc | ||
|
|
4f4b3ce8c6 | ||
|
|
c42feec312 | ||
|
|
ba567efc22 | ||
|
|
cbb24a2c40 | ||
|
|
da21675f03 | ||
|
|
8883d98b00
|
||
|
|
cf907089da
|
||
|
|
070fe7add0 | ||
|
|
2d40ce33d1 | ||
|
|
052e3a7800 | ||
|
|
ec80adf0a5 | ||
|
|
88a2808a47 | ||
|
|
a13daf27a6 | ||
|
|
75de349ff4 | ||
|
|
439a14d29e | ||
|
|
bf5a8b8049 | ||
|
|
a9bbb21f54 | ||
|
|
bb50cf756d | ||
|
|
57147dc7c1 | ||
|
|
620fe001a4 | ||
|
|
85320e9ea1 | ||
|
|
259a4dde7a | ||
|
|
d6230bef34 | ||
|
|
4ee9bb3f12 | ||
|
|
8789d2d322 | ||
|
|
954dc10fbb | ||
|
|
15ccfd24c6 | ||
|
|
33b08523e9 | ||
|
|
742bece30b | ||
|
|
a64eadd14a | ||
|
|
f9eeb793db | ||
|
|
6bb193c78c | ||
|
|
aadecbfe44 | ||
|
|
53f0aa80ae | ||
|
|
d9856c9409 | ||
|
|
8dc9753e2b | ||
|
|
2a4bd3dfdd | ||
|
|
f75f51ef50 | ||
|
|
e0873304d1 | ||
|
|
99a0155c17 | ||
|
|
f309debea5 | ||
|
|
0979fd014d | ||
|
|
656bd0a54d | ||
|
|
f01001dcfa | ||
|
|
bc6b0d50ab | ||
|
|
f27c9afc25 | ||
|
|
5962fc8354 | ||
|
|
1adcb9841c | ||
|
|
0e0f8555ed | ||
|
|
1d63e67554 |
+22
-87
@@ -1,12 +1,15 @@
|
||||
name: Python
|
||||
|
||||
env:
|
||||
APT_DEPS: git python3 python3-pip python3-venv python3-gi python3-cairo python3-dbus python3-pyudev python3-psutil python3-evdev python3-yaml python3-xlib python3-pillow gir1.2-gtk-3.0
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
fmt:
|
||||
runs-on: alpine
|
||||
container: node:26-alpine
|
||||
static:
|
||||
runs-on: debian
|
||||
container: node:26-trixie-slim
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
@@ -14,10 +17,8 @@ jobs:
|
||||
|
||||
- name: Install tools
|
||||
run: |
|
||||
apk add --no-cache \
|
||||
git \
|
||||
python3 \
|
||||
py3-pip
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends git python3 python3-pip python3-venv
|
||||
python3 -m venv .venv
|
||||
. .venv/bin/activate
|
||||
pip install --no-cache-dir ruff
|
||||
@@ -27,32 +28,15 @@ jobs:
|
||||
. .venv/bin/activate
|
||||
ruff format --check .
|
||||
|
||||
lint:
|
||||
runs-on: alpine
|
||||
container: node:26-alpine
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install tools
|
||||
run: |
|
||||
apk add --no-cache \
|
||||
git \
|
||||
python3 \
|
||||
py3-pip
|
||||
python3 -m venv .venv
|
||||
. .venv/bin/activate
|
||||
pip install --no-cache-dir ruff
|
||||
|
||||
- name: Lint
|
||||
run: |
|
||||
. .venv/bin/activate
|
||||
ruff check .
|
||||
|
||||
test:
|
||||
runs-on: alpine
|
||||
container: node:26-alpine
|
||||
verify:
|
||||
if: always()
|
||||
runs-on: debian
|
||||
container: node:26-trixie-slim
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
@@ -60,20 +44,16 @@ jobs:
|
||||
|
||||
- name: Install tools
|
||||
run: |
|
||||
apk add --no-cache \
|
||||
git \
|
||||
python3 \
|
||||
py3-pip \
|
||||
py3-pillow \
|
||||
build-base
|
||||
python3 -m venv .venv
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends $APT_DEPS build-essential python3-dev
|
||||
python3 -m venv --system-site-packages .venv
|
||||
. .venv/bin/activate
|
||||
pip install --no-cache-dir \
|
||||
typer \
|
||||
pillow \
|
||||
materialyoucolor \
|
||||
jinja2 \
|
||||
pytest
|
||||
pip install --no-cache-dir basedpyright nuitka .
|
||||
|
||||
- name: Type check
|
||||
run: |
|
||||
. .venv/bin/activate
|
||||
basedpyright
|
||||
|
||||
- name: Test
|
||||
run: |
|
||||
@@ -81,52 +61,7 @@ jobs:
|
||||
cd cli
|
||||
python -m pytest tests/ -v
|
||||
|
||||
typecheck:
|
||||
runs-on: alpine
|
||||
container: node:26-alpine
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install tools
|
||||
run: |
|
||||
apk add --no-cache \
|
||||
git \
|
||||
python3 \
|
||||
py3-pip
|
||||
python3 -m venv .venv
|
||||
. .venv/bin/activate
|
||||
pip install --no-cache-dir basedpyright typer pillow materialyoucolor jinja2
|
||||
|
||||
- name: Type check
|
||||
run: |
|
||||
. .venv/bin/activate
|
||||
basedpyright
|
||||
|
||||
buildcheck:
|
||||
runs-on: alpine
|
||||
container: node:26-alpine
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install tools
|
||||
run: |
|
||||
apk add --no-cache \
|
||||
git \
|
||||
python3 \
|
||||
py3-pip \
|
||||
build-base \
|
||||
python3-dev \
|
||||
gcc \
|
||||
g++
|
||||
python3 -m venv .venv
|
||||
. .venv/bin/activate
|
||||
pip install --no-cache-dir nuitka
|
||||
|
||||
- name: Nuitka module check
|
||||
run: |
|
||||
. .venv/bin/activate
|
||||
nuitka --module --include-package=zshell cli/src/zshell/
|
||||
nuitka --module --include-package=zshell cli/src/zshell/
|
||||
@@ -16,3 +16,5 @@ dist/
|
||||
**/test-plugins/
|
||||
**/Charts/
|
||||
network-dev/
|
||||
**/zshell.build/
|
||||
**/zshell.dist/
|
||||
|
||||
@@ -93,6 +93,8 @@ if("shell" IN_LIST ENABLE_MODULES)
|
||||
${NUITKA_EXECUTABLE}
|
||||
--standalone
|
||||
--include-data-dir=${CMAKE_SOURCE_DIR}/cli/src/zshell/assets=zshell/assets
|
||||
--include-package=gi.overrides
|
||||
--include-package-data=solaar
|
||||
--output-dir=${ZSHELL_CLI_BUILD_DIR}
|
||||
--output-filename=zshell-cli
|
||||
${CMAKE_SOURCE_DIR}/cli/src/zshell/
|
||||
|
||||
@@ -15,7 +15,7 @@ CustomRect {
|
||||
property color activeOnColor
|
||||
property bool checked
|
||||
property real checkedRadius: Tokens.rounding.medium
|
||||
property real defaultRadius: Tokens.rounding.large
|
||||
property real defaultRadius: Math.min(width, height) / 2
|
||||
property color disabledColor: Qt.alpha(Colors.palette.m3onSurface, 0.1)
|
||||
property color disabledOnColor: Qt.alpha(Colors.palette.m3onSurface, 0.38)
|
||||
property bool fillWidth
|
||||
|
||||
@@ -34,6 +34,7 @@ BusyIndicator {
|
||||
anchors.fill: parent
|
||||
bgColor: root.bgColor
|
||||
fgColor: root.fgColor
|
||||
hasEndIndicator: false
|
||||
padding: root.padding
|
||||
rotation: manager.rotation
|
||||
startAngle: manager.startFraction * 360
|
||||
@@ -53,6 +54,7 @@ BusyIndicator {
|
||||
Anim {
|
||||
duration: manager.completeEndDuration * Tokens.anim.durations.scale
|
||||
properties: "opacity,internalStrokeWidth"
|
||||
type: Anim.DefaultEffects
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,13 @@ Slider {
|
||||
|
||||
property bool animateWave
|
||||
property color bgColor: enabled ? Colors.palette.m3secondaryContainer : Qt.alpha(Colors.palette.m3onSurface, 0.1)
|
||||
readonly property bool dragging: mouse.pressed
|
||||
property color fgColor: enabled ? Colors.palette.m3primary : Qt.alpha(Colors.palette.m3onSurface, 0.38)
|
||||
property real filledWidth
|
||||
property alias inset: inset
|
||||
property color insetColor: enabled ? (inset.attached ? Colors.palette.m3onSecondaryContainer : Colors.palette.m3onPrimary) : Colors.palette.m3onSurface
|
||||
property string insetIcon: ""
|
||||
property bool interactionOnMove: true
|
||||
property real pos: visualPosition
|
||||
property int radius: Tokens.rounding.small
|
||||
property int waveDuration: 1000
|
||||
@@ -139,7 +141,7 @@ Slider {
|
||||
CAnim {
|
||||
}
|
||||
}
|
||||
Anim on waveProgress {
|
||||
NumberAnimation on waveProgress {
|
||||
duration: root.waveDuration
|
||||
easing.type: Easing.Linear
|
||||
from: 0
|
||||
@@ -186,7 +188,8 @@ Slider {
|
||||
|
||||
onPositionChanged: e => {
|
||||
dragMovement = (e.x - pressStartX) / width;
|
||||
root.interaction(posBinding.value);
|
||||
if (root.interactionOnMove)
|
||||
root.interaction(posBinding.value);
|
||||
}
|
||||
onPressed: e => {
|
||||
widthBehavior.enabled = false;
|
||||
|
||||
@@ -23,6 +23,7 @@ TextFieldBase {
|
||||
property string leadingIcon
|
||||
readonly property int leadingOffset: leadingIcon ? leadingIconLoader.width + leadingIconLoader.anchors.leftMargin : 0
|
||||
property int radius: Tokens.rounding.small
|
||||
property alias sLayer: stateLayer
|
||||
readonly property real smallFontScale: smallFontSize / font.pointSize
|
||||
property int smallFontSize: Tokens.font.size.small
|
||||
property string supportingText
|
||||
@@ -145,6 +146,7 @@ TextFieldBase {
|
||||
|
||||
sourceComponent: MaterialIcon {
|
||||
color: Colors.palette.m3onSurfaceVariant
|
||||
font.pointSize: Tokens.font.size.larger
|
||||
text: root.leadingIcon
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
import QtQuick
|
||||
import ZShell.Config
|
||||
import qs.Components
|
||||
@@ -15,6 +16,9 @@ Scope {
|
||||
ExclusionZone {
|
||||
id: top
|
||||
|
||||
WlrLayershell.layer: WlrLayer.Overlay
|
||||
anchors.left: true
|
||||
anchors.right: true
|
||||
anchors.top: true
|
||||
hasBar: root.geometry.barOnTop
|
||||
}
|
||||
|
||||
@@ -162,6 +162,19 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: unhideTimer
|
||||
|
||||
interval: Config.bar.revealDelay
|
||||
repeat: false
|
||||
running: false
|
||||
|
||||
onTriggered: {
|
||||
if (hoverHandler.hovered)
|
||||
root.bar.isHovered = true;
|
||||
}
|
||||
}
|
||||
|
||||
HoverHandler {
|
||||
id: hoverHandler
|
||||
|
||||
@@ -178,7 +191,7 @@ Item {
|
||||
root.popouts.hasCurrent = false;
|
||||
}
|
||||
|
||||
if (Config.bar.autoHide)
|
||||
if (Config.bar.autoHide || root.bar.fullscreen)
|
||||
root.bar.isHovered = false;
|
||||
}
|
||||
}
|
||||
@@ -200,6 +213,9 @@ Item {
|
||||
if (!root.visibilities.bar && Config.bar.autoHide && root.geometry.barContains(x, y, true))
|
||||
root.bar.isHovered = true;
|
||||
|
||||
if (root.bar.fullscreen && !root.bar.isHovered)
|
||||
unhideTimer.start();
|
||||
|
||||
if (root.panels.sidebar.offsetScale === 1) {
|
||||
const showOsd = root.inRightPanel(root.panels.osdWrapper, x, y);
|
||||
|
||||
@@ -220,7 +236,7 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.dock.enable && Config.dock.hoverToReveal && !root.visibilities.dock && !root.visibilities.launcher && root.inBottomPanel(root.panels.dock, x, y))
|
||||
if (Config.dock.enabled && Config.dock.hoverToReveal && !root.visibilities.dock && !root.visibilities.launcher && root.inBottomPanel(root.panels.dock, x, y))
|
||||
root.visibilities.dock = true;
|
||||
|
||||
if (root.geometry.barContains(x, y))
|
||||
|
||||
+20
-3
@@ -11,6 +11,7 @@ import ZShell.Blobs
|
||||
import qs.Daemons
|
||||
import qs.Components
|
||||
import qs.Modules.Bar
|
||||
import qs.Modules.Bar.Popouts.Network as N
|
||||
import ZShell.Config
|
||||
import qs.Helpers
|
||||
import qs.Drawers
|
||||
@@ -51,7 +52,7 @@ CustomWindow {
|
||||
readonly property HyprlandMonitor monitor: Hypr.monitorFor(screen)
|
||||
property var root: Quickshell.shellDir
|
||||
readonly property real sdfBorderOffset: 2 * fsTransitionProg
|
||||
readonly property real shadowOpacity: 0.7 * (1 - fsTransitionProg)
|
||||
readonly property real shadowOpacity: 0.7 * (1 - (bar.isHovered ? 0 : fsTransitionProg))
|
||||
property color surfaceColor: Colors.tPalette.m3surface
|
||||
|
||||
WlrLayershell.exclusionMode: ExclusionMode.Ignore
|
||||
@@ -59,7 +60,7 @@ CustomWindow {
|
||||
WlrLayershell.layer: (fsTransitionProg > 0 && Config.general.showOverFullscreen) || (hasSpecialWorkspace && hasFullscreenOnNormalWs) ? WlrLayer.Overlay : WlrLayer.Top
|
||||
color: "transparent"
|
||||
contentItem.focus: true
|
||||
mask: visibilities.isDrawing ? null : (hasFullscreen ? emptyRegion : regions)
|
||||
mask: visibilities.isDrawing ? null : (hasFullscreen && !bar.isHovered ? emptyRegion : regions)
|
||||
name: "Bar"
|
||||
|
||||
Behavior on fsTransitionProg {
|
||||
@@ -118,6 +119,12 @@ CustomWindow {
|
||||
x: root.width - width
|
||||
y: panels.osdWrapper.y + bar.implicitHeight
|
||||
}
|
||||
|
||||
Region {
|
||||
height: geometry.horizontal ? 1 : root.screen.height
|
||||
width: geometry.horizontal ? root.screen.width : 1
|
||||
y: geometry.position === "bottom" ? root.screen.height - 1 : 0
|
||||
}
|
||||
}
|
||||
|
||||
Regions {
|
||||
@@ -138,7 +145,17 @@ CustomWindow {
|
||||
HyprlandFocusGrab {
|
||||
id: focusGrab
|
||||
|
||||
active: visibilities.dock || visibilities.resources || visibilities.launcher || visibilities.sidebar || visibilities.dashboard || visibilities.settings || visibilities.clipboard || (panels.popouts.hasCurrent && panels.popouts.currentName.startsWith("traymenu") && (!Config.bar.tray.showOnHover || (panels.popouts.current as StackView)?.depth > 1))
|
||||
active: {
|
||||
const v = visibilities;
|
||||
const conf = Config;
|
||||
if (!N.PopupManager.closed && panels.popouts.hasCurrent)
|
||||
return true;
|
||||
if ((v.launcher && conf.launcher.enabled) || (v.sidebar && conf.sidebar.enabled) || (v.resources && conf.dashboard.performance.enabled) || (v.dashboard && conf.dashboard.enabled) || v.settings || (v.clipboard && conf.clipboard.enabled) || (v.dock && conf.dock.enabled))
|
||||
return true;
|
||||
if (panels.popouts.hasCurrent && panels.popouts.currentName.startsWith("traymenu") && (!conf.bar.tray.showOnHover || (panels.popouts.current as StackView)?.depth > 1))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
windows: [root]
|
||||
|
||||
onCleared: {
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
import QtQuick
|
||||
import QtQuick.Effects
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property real radius
|
||||
|
||||
Rectangle {
|
||||
id: shadowRect
|
||||
|
||||
anchors.fill: root
|
||||
color: "black"
|
||||
layer.enabled: true
|
||||
radius: root.radius
|
||||
visible: false
|
||||
}
|
||||
|
||||
MultiEffect {
|
||||
id: effects
|
||||
|
||||
anchors.fill: shadowRect
|
||||
autoPaddingEnabled: true
|
||||
maskEnabled: true
|
||||
maskInverted: true
|
||||
maskSource: shadowRect
|
||||
shadowBlur: 2.0
|
||||
shadowColor: "black"
|
||||
shadowEnabled: true
|
||||
shadowOpacity: 1
|
||||
source: shadowRect
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import ZShell.Config
|
||||
import qs.Services
|
||||
|
||||
@@ -11,6 +10,6 @@ TextInput {
|
||||
font {
|
||||
family: Config.appearance?.font.family.sans ?? "sans-serif"
|
||||
hintingPreference: Font.PreferFullHinting
|
||||
pixelSize: Config.appearance?.font.size.normal ?? 15
|
||||
pixelSize: Tokens?.font.size.normal ?? 15
|
||||
}
|
||||
}
|
||||
|
||||
+40
-12
@@ -1,35 +1,63 @@
|
||||
pragma Singleton
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Services.UPower
|
||||
import ZShell.Config
|
||||
import qs.Services
|
||||
import qs.Paths
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
readonly property var colors: {
|
||||
if (deviceState === UPowerDeviceState.Charging || deviceState === UPowerDeviceState.FullyCharged)
|
||||
readonly property list<var> allPeripherals: [...logiDevices, ...upowerDevices.filter(d => !Battery.logiDevices.some(l => l.nativePath === d.nativePath))]
|
||||
readonly property real currentPerc: UPower.displayDevice.percentage
|
||||
readonly property var deviceState: UPower.displayDevice.state
|
||||
readonly property string deviceStateString: UPowerDeviceState.toString(deviceState)
|
||||
readonly property bool isLaptop: UPower.displayDevice.isLaptopBattery
|
||||
readonly property alias logiDevices: adapter.devices
|
||||
readonly property var lowestPeripheral: allPeripherals.reduce((lowest, current) => current.percentage < lowest.percentage ? current : lowest)
|
||||
readonly property bool onBattery: UPower.onBattery
|
||||
readonly property bool ready: UPower.displayDevice.ready
|
||||
readonly property real timeToEmpty: UPower.displayDevice.timeToEmpty
|
||||
readonly property real timeToFull: UPower.displayDevice.timeToFull
|
||||
readonly property list<UPowerDevice> upowerDevices: UPower.devices.values.filter(d => d.state !== UPowerDeviceState.Unknown)
|
||||
|
||||
function getColors(percentage: real, state: string): var {
|
||||
if (state === "charging" || state === "full" || state === "recharging")
|
||||
return {
|
||||
fg: Colors.swapRG(Colors.palette.m3error),
|
||||
bg: Colors.swapRG(Colors.palette.m3onError)
|
||||
};
|
||||
else if (currentPerc <= 0.2)
|
||||
else if (percentage <= 0.2)
|
||||
return {
|
||||
fg: Colors.palette.m3error,
|
||||
bg: Colors.palette.m3onError
|
||||
};
|
||||
else
|
||||
return {
|
||||
fg: Colors.palette.m3onSurface,
|
||||
bg: Colors.palette.m3surface
|
||||
fg: Colors.palette.m3tertiary,
|
||||
bg: Colors.palette.m3onTertiary
|
||||
};
|
||||
}
|
||||
readonly property real currentPerc: UPower.displayDevice.percentage
|
||||
readonly property var deviceState: UPower.displayDevice.state
|
||||
readonly property bool isLaptop: UPower.displayDevice.isLaptopBattery
|
||||
readonly property bool onBattery: UPower.onBattery
|
||||
readonly property bool ready: UPower.displayDevice.ready
|
||||
readonly property real timeToEmpty: UPower.displayDevice.timeToEmpty
|
||||
readonly property real timeToFull: UPower.displayDevice.timeToFull
|
||||
|
||||
function startDaemon(): void {
|
||||
Quickshell.execDetached(["zshell-cli", "battery", "daemon"]);
|
||||
}
|
||||
|
||||
FileView {
|
||||
id: fileView
|
||||
|
||||
path: `${Paths.cache}/battery.json`
|
||||
watchChanges: true
|
||||
|
||||
onFileChanged: reload()
|
||||
|
||||
JsonAdapter {
|
||||
id: adapter
|
||||
|
||||
property list<var> devices: []
|
||||
property real updated: 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
import qs.Components
|
||||
import ZShell.Config
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property list<var> apps: {
|
||||
var map = new Map();
|
||||
|
||||
const pinnedApps = Config.dock?.pinnedApps ?? [];
|
||||
for (const appId of pinnedApps) {
|
||||
if (!map.has(appId.toLowerCase()))
|
||||
map.set(appId.toLowerCase(), ({
|
||||
pinned: true,
|
||||
toplevels: []
|
||||
}));
|
||||
}
|
||||
|
||||
if (pinnedApps.length > 0) {
|
||||
map.set("SEPARATOR", {
|
||||
pinned: false,
|
||||
toplevels: []
|
||||
});
|
||||
}
|
||||
|
||||
var values = [];
|
||||
|
||||
for (const [key, value] of map) {
|
||||
values.push(appEntryComp.createObject(null, {
|
||||
appId: key,
|
||||
toplevels: value.toplevels,
|
||||
pinned: value.pinned
|
||||
}));
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
function isPinned(appId) {
|
||||
return Config.dock.pinnedApps.indexOf(appId) !== -1;
|
||||
}
|
||||
|
||||
function togglePin(appId) {
|
||||
if (root.isPinned(appId)) {
|
||||
Config.dock.pinnedApps = Config.dock.pinnedApps.filter(id => id !== appId);
|
||||
} else {
|
||||
Config.dock.pinnedApps = Config.dock.pinnedApps.concat([appId]);
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: appEntryComp
|
||||
|
||||
TaskbarAppEntry {
|
||||
}
|
||||
}
|
||||
|
||||
component TaskbarAppEntry: QtObject {
|
||||
id: wrapper
|
||||
|
||||
required property string appId
|
||||
required property bool pinned
|
||||
required property list<var> toplevels
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
// FetchPresets.qml
|
||||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property var parsedPresets: ({})
|
||||
readonly property var presets: parsedPresets
|
||||
property bool ready: false
|
||||
|
||||
function accents(presetName, variantName) {
|
||||
const variant = parsedPresets[presetName]?.variants?.[variantName];
|
||||
|
||||
return variant?.accents ?? [];
|
||||
}
|
||||
|
||||
function defaultAccent(presetName, variantName) {
|
||||
const variant = parsedPresets[presetName]?.variants?.[variantName];
|
||||
|
||||
return variant?.default_accent ?? "";
|
||||
}
|
||||
|
||||
function modes(presetName, variantName) {
|
||||
const variant = parsedPresets[presetName]?.variants?.[variantName];
|
||||
|
||||
return variant?.modes ?? [];
|
||||
}
|
||||
|
||||
function presetNames() {
|
||||
return Object.keys(parsedPresets);
|
||||
}
|
||||
|
||||
function variantNames(presetName) {
|
||||
const preset = parsedPresets[presetName];
|
||||
|
||||
if (!preset || !preset.variants)
|
||||
return [];
|
||||
|
||||
return Object.keys(preset.variants);
|
||||
}
|
||||
|
||||
Process {
|
||||
command: ["zshell-cli", "scheme", "list-presets", "--json"]
|
||||
running: true
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
try {
|
||||
const parsed = JSON.parse(text);
|
||||
|
||||
root.parsedPresets = parsed.presets ?? {};
|
||||
root.ready = true;
|
||||
} catch (e) {
|
||||
console.error("Failed to parse presets JSON:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,16 +77,6 @@ Singleton {
|
||||
"99": "thunderstorm"
|
||||
})
|
||||
|
||||
function getAppCategoryIcon(name: string, fallback: string): string {
|
||||
const categories = DesktopEntries.heuristicLookup(name)?.categories;
|
||||
|
||||
if (categories)
|
||||
for (const [key, value] of Object.entries(categoryIcons))
|
||||
if (categories.includes(key))
|
||||
return value;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
function getAppIcon(name: string, fallback: string): string {
|
||||
const icon = DesktopEntries.heuristicLookup(name)?.icon;
|
||||
if (fallback !== "undefined")
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
pragma Singleton
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Networking
|
||||
import QtQuick
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property bool active: false
|
||||
readonly property list<Network> connectedNetworks: networks.filter(n => n.connected)
|
||||
property Network connectingNetwork
|
||||
readonly property list<NetworkDevice> devices: Networking.devices.values
|
||||
property Network failedNetwork
|
||||
readonly property list<Network> knownNetworks: networks.filter(n => n.known && !n.connected)
|
||||
readonly property list<Network> networks: {
|
||||
const list = [];
|
||||
for (const d of wifiDevices) {
|
||||
for (const n of d.networks.values) {
|
||||
if (!list.includes(n))
|
||||
list.push(n);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
property bool scanning: false
|
||||
readonly property list<Network> unknownNetworks: networks.filter(n => !n.known)
|
||||
readonly property list<WifiDevice> wifiDevices: devices.filter(d => wifiDevice(d))
|
||||
readonly property bool wifiEnabled: Networking.wifiEnabled
|
||||
|
||||
signal networkConnected
|
||||
|
||||
function isSecure(security): bool {
|
||||
return (security === WifiSecurityType.WpaPsk || security === WifiSecurityType.Wpa2Psk || security === WifiSecurityType.Sae);
|
||||
}
|
||||
|
||||
function requestConnect(network: Network, secret = undefined): void {
|
||||
connectingNetwork = network;
|
||||
if (secret === undefined || secret === "") {
|
||||
network.connect();
|
||||
} else {
|
||||
(network as WifiNetwork).connectWithPsk(secret);
|
||||
}
|
||||
}
|
||||
|
||||
function setScan(value: bool): void {
|
||||
for (const d of wifiDevices) {
|
||||
d.scannerEnabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
function setWifi(value: bool): void {
|
||||
Networking.wifiEnabled = value;
|
||||
}
|
||||
|
||||
function wifiDevice(dev): bool {
|
||||
return dev.type === DeviceType.Wifi;
|
||||
}
|
||||
|
||||
onActiveChanged: {
|
||||
for (const d of wifiDevices)
|
||||
d.scannerEnabled = active;
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: flushFailed
|
||||
|
||||
interval: 5000
|
||||
running: root.failedNetwork
|
||||
|
||||
onTriggered: {
|
||||
root.failedNetwork = null;
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: checkConnection
|
||||
|
||||
interval: 500
|
||||
repeat: true
|
||||
running: root.connectingNetwork
|
||||
|
||||
onTriggered: {
|
||||
var completedNetwork;
|
||||
|
||||
switch (root.connectingNetwork.state) {
|
||||
case ConnectionState.Connecting:
|
||||
break;
|
||||
case ConnectionState.Connected:
|
||||
completedNetwork = root.connectingNetwork;
|
||||
root.networkConnected();
|
||||
break;
|
||||
case ConnectionState.Disconnected:
|
||||
root.failedNetwork = root.connectingNetwork;
|
||||
completedNetwork = root.connectingNetwork;
|
||||
break;
|
||||
}
|
||||
|
||||
if (completedNetwork) {
|
||||
root.connectingNetwork = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 10000
|
||||
running: checkConnection.running
|
||||
|
||||
onTriggered: {
|
||||
root.failedNetwork = root.connectingNetwork;
|
||||
root.connectingNetwork = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-41
@@ -11,8 +11,8 @@ Singleton {
|
||||
id: root
|
||||
|
||||
property int availableUpdates: 0
|
||||
property string cmd: ""
|
||||
property bool commandReady
|
||||
property bool hasHelper
|
||||
property bool loaded
|
||||
property double now: Date.now()
|
||||
property var updates: ({})
|
||||
@@ -38,18 +38,12 @@ Singleton {
|
||||
}
|
||||
|
||||
function performPackageUpdate(pkg: string): void {
|
||||
if (root.cmd === "pacman")
|
||||
pkgUpdateProc.command = ["pkexec", root.cmd, "--noconfirm", "-Sy", pkg];
|
||||
else
|
||||
pkgUpdateProc.command = [root.cmd, "--noconfirm", "--sudo", "pkexec", "-Sy", pkg];
|
||||
pkgUpdateProc.command = ["pkexec", "pacman", "--noconfirm", "-Sy", pkg];
|
||||
pkgUpdateProc.running = true;
|
||||
}
|
||||
|
||||
function performSystemUpdate(): void {
|
||||
if (root.cmd === "pacman")
|
||||
sysUpdateProc.command = ["pkexec", root.cmd, "--noconfirm", "-Syu"];
|
||||
else
|
||||
sysUpdateProc.command = [root.cmd, "--noconfirm", "--sudo", "pkexec", "-Syu"];
|
||||
sysUpdateProc.command = ["pkexec", "pacman", "--noconfirm", "-Syu"];
|
||||
sysUpdateProc.running = true;
|
||||
}
|
||||
|
||||
@@ -87,7 +81,7 @@ Singleton {
|
||||
Process {
|
||||
id: cmdDetect
|
||||
|
||||
command: ["sh", "-c", "command -v checkupdates || command -v yay || command -v paru"]
|
||||
command: ["sh", "-c", "command -v checkupdates"]
|
||||
running: true
|
||||
|
||||
stdout: StdioCollector {
|
||||
@@ -96,47 +90,20 @@ Singleton {
|
||||
let helper;
|
||||
|
||||
if (cmd.length > 0) {
|
||||
helper = cmd.split("/").pop();
|
||||
helper = true;
|
||||
} else {
|
||||
helper = "pacman";
|
||||
}
|
||||
|
||||
if (helper === "checkupdates") {
|
||||
updatesProc.command = [helper];
|
||||
} else {
|
||||
updatesProc.command = [helper, "-Qu"];
|
||||
helper = false;
|
||||
}
|
||||
root.hasHelper = helper;
|
||||
root.commandReady = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: updateCmdDetect
|
||||
|
||||
command: ["sh", "-c", "command -v yay || command -v paru"]
|
||||
running: true
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
const cmd = this.text.trim();
|
||||
let helper;
|
||||
|
||||
if (cmd.length > 0) {
|
||||
helper = cmd.split("/").pop();
|
||||
} else {
|
||||
helper = "pacman";
|
||||
}
|
||||
|
||||
root.cmd = helper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: updatesProc
|
||||
|
||||
command: []
|
||||
command: root.hasHelper ? ["checkupdates"] : []
|
||||
running: false
|
||||
|
||||
stdout: StdioCollector {
|
||||
|
||||
@@ -17,7 +17,10 @@ Singleton {
|
||||
watchChanges: true
|
||||
|
||||
onAdapterUpdated: writeAdapter()
|
||||
onFileChanged: reload()
|
||||
onFileChanged: {
|
||||
reload();
|
||||
Wallpapers.previewColorLock = false;
|
||||
}
|
||||
|
||||
JsonAdapter {
|
||||
id: adapter
|
||||
|
||||
+28
-6
@@ -6,7 +6,7 @@ import Quickshell.Io
|
||||
import QtQuick
|
||||
import ZShell.Models
|
||||
import ZShell.Config
|
||||
import qs.Modules
|
||||
import qs.Services
|
||||
import qs.Helpers
|
||||
import qs.Paths
|
||||
|
||||
@@ -17,6 +17,8 @@ Searcher {
|
||||
property alias crops: adapter.monitorCrops
|
||||
readonly property string current: showPreview ? previewPath : actualCurrent
|
||||
property alias monitorCrops: monitorCrops
|
||||
property bool pendingPreviewClear
|
||||
property bool previewColorLock
|
||||
property string previewPath
|
||||
property bool recentlyChanged
|
||||
property bool showPreview: false
|
||||
@@ -34,9 +36,10 @@ Searcher {
|
||||
|
||||
function preview(path: string): void {
|
||||
previewPath = path;
|
||||
if (Config.general.color.schemeGeneration)
|
||||
Quickshell.execDetached(["zshell-cli", "scheme", "generate", "--image-path", `${previewPath}`, "--scheme", `${Config.colors.schemeType}`, "--mode", `${Config.general.color.mode}`]);
|
||||
showPreview = true;
|
||||
|
||||
if (Config.general.color.schemeGeneration)
|
||||
previewColorsProc.running = true;
|
||||
}
|
||||
|
||||
function setCrop(screen: string, rect: rect, zoom: real): void {
|
||||
@@ -52,7 +55,6 @@ Searcher {
|
||||
height: rect.height,
|
||||
zoom: zoom
|
||||
};
|
||||
// root.crops = updated;
|
||||
}
|
||||
|
||||
function setWallpaper(path: string): void {
|
||||
@@ -66,8 +68,10 @@ Searcher {
|
||||
|
||||
function stopPreview(): void {
|
||||
showPreview = false;
|
||||
if (Config.general.color.schemeGeneration)
|
||||
Quickshell.execDetached(["zshell-cli", "scheme", "generate", "--image-path", `${root.actualCurrent}`, "--scheme", `${Config.colors.schemeType}`, "--mode", `${Config.general.color.mode}`]);
|
||||
if (previewColorLock)
|
||||
pendingPreviewClear = true;
|
||||
else
|
||||
Colors.showPreview = false;
|
||||
}
|
||||
|
||||
extraOpts: useFuzzy ? ({}) : ({
|
||||
@@ -77,6 +81,11 @@ Searcher {
|
||||
list: wallpapers.entries
|
||||
useFuzzy: true
|
||||
|
||||
onPreviewColorLockChanged: {
|
||||
if (!previewColorLock && pendingPreviewClear)
|
||||
Colors.showPreview = false;
|
||||
}
|
||||
|
||||
IpcHandler {
|
||||
function set(path: string): void {
|
||||
root.setWallpaper(path);
|
||||
@@ -118,4 +127,17 @@ Searcher {
|
||||
path: Config.general.wallpaperPath
|
||||
recursive: true
|
||||
}
|
||||
|
||||
Process {
|
||||
id: previewColorsProc
|
||||
|
||||
command: ["zshell-cli", "scheme", "generate", "-p", "-i", root.previewPath]
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
Colors.load(text, true);
|
||||
Colors.showPreview = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-18
@@ -12,6 +12,7 @@ GridLayout {
|
||||
|
||||
required property bool fullscreen
|
||||
required property bool horizontal
|
||||
required property bool isHovered
|
||||
required property Wrapper popouts
|
||||
required property ClipWrapper popoutsWrapper
|
||||
required property ShellScreen screen
|
||||
@@ -92,7 +93,7 @@ GridLayout {
|
||||
delegate: EntryWrapper {
|
||||
HyprsunsetWidget {
|
||||
horizontal: root.horizontal
|
||||
visible: !root.fullscreen
|
||||
visible: !root.fullscreen || root.isHovered
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,7 +114,7 @@ GridLayout {
|
||||
Workspaces {
|
||||
horizontal: root.horizontal
|
||||
screen: root.screen
|
||||
visible: !root.fullscreen
|
||||
visible: !root.fullscreen || root.isHovered
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +127,7 @@ GridLayout {
|
||||
horizontal: root.horizontal
|
||||
loader: root
|
||||
popouts: root.popouts
|
||||
visible: !root.fullscreen
|
||||
visible: !root.fullscreen || root.isHovered
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,6 +138,7 @@ GridLayout {
|
||||
delegate: EntryWrapper {
|
||||
StatusIcons {
|
||||
horizontal: root.horizontal
|
||||
visible: !root.fullscreen || root.isHovered
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,7 +150,7 @@ GridLayout {
|
||||
Resources {
|
||||
horizontal: root.horizontal
|
||||
visibilities: root.visibilities
|
||||
visible: !root.fullscreen
|
||||
visible: !root.fullscreen || root.isHovered
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +161,7 @@ GridLayout {
|
||||
delegate: EntryWrapper {
|
||||
UpdatesWidget {
|
||||
horizontal: root.horizontal
|
||||
visible: !root.fullscreen
|
||||
visible: !root.fullscreen || root.isHovered
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,7 +174,7 @@ GridLayout {
|
||||
horizontal: root.horizontal
|
||||
popouts: root.popouts
|
||||
visibilities: root.visibilities
|
||||
visible: !root.fullscreen
|
||||
visible: !root.fullscreen || root.isHovered
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,7 +188,7 @@ GridLayout {
|
||||
loader: root
|
||||
popouts: root.popouts
|
||||
visibilities: root.visibilities
|
||||
visible: !root.fullscreen
|
||||
visible: !root.fullscreen || root.isHovered
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,16 +200,7 @@ GridLayout {
|
||||
WindowTitle {
|
||||
bar: root
|
||||
horizontal: root.horizontal
|
||||
visible: !root.fullscreen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DelegateChoice {
|
||||
roleValue: "network"
|
||||
|
||||
delegate: EntryWrapper {
|
||||
NetworkWidget {
|
||||
visible: !root.fullscreen || root.isHovered
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,7 +211,7 @@ GridLayout {
|
||||
delegate: EntryWrapper {
|
||||
MediaWidget {
|
||||
horizontal: root.horizontal
|
||||
visible: !root.fullscreen
|
||||
visible: !root.fullscreen || root.isHovered
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ Item {
|
||||
required property ClipWrapper popoutsWrapper
|
||||
required property string position
|
||||
required property ShellScreen screen
|
||||
readonly property bool shouldBeVisible: !fullscreen && (!Config.bar.autoHide || visibilities.bar || isHovered)
|
||||
readonly property bool shouldBeVisible: (!fullscreen && (!Config.bar.autoHide || visibilities.bar)) || isHovered
|
||||
readonly property int vPadding: 6
|
||||
required property PersistentProperties visibilities
|
||||
|
||||
@@ -79,7 +79,9 @@ Item {
|
||||
|
||||
sourceComponent: Bar {
|
||||
fullscreen: root.fullscreen
|
||||
height: root.contentThickness
|
||||
horizontal: root.horizontal
|
||||
isHovered: root.isHovered
|
||||
popouts: root.popouts
|
||||
popoutsWrapper: root.popoutsWrapper
|
||||
screen: root.screen
|
||||
|
||||
@@ -57,7 +57,7 @@ WidgetBase {
|
||||
|
||||
anchors.centerIn: parent
|
||||
color: root.contentColor
|
||||
font: Config.appearance.font.family.mono // qmllint disable incompatible-type
|
||||
font.family: Config.appearance.font.family.mono // qmllint disable incompatible-type
|
||||
height: implicitHeight
|
||||
text: Time.dateStr
|
||||
visible: root.horizontal
|
||||
@@ -84,7 +84,7 @@ WidgetBase {
|
||||
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
color: root.contentColor
|
||||
font: Config.appearance.font.family.mono // qmllint disable incompatible-type
|
||||
font.family: Config.appearance.font.family.mono // qmllint disable incompatible-type
|
||||
text: Qt.formatDateTime(Time.date, modelData)
|
||||
|
||||
Behavior on color {
|
||||
@@ -114,7 +114,7 @@ WidgetBase {
|
||||
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
color: root.contentColor
|
||||
font: Config.appearance.font.family.mono // qmllint disable incompatible-type
|
||||
font.family: Config.appearance.font.family.mono // qmllint disable incompatible-type
|
||||
text: {
|
||||
if (modelData.includes("h"))
|
||||
return Time.hourStr;
|
||||
@@ -135,7 +135,7 @@ WidgetBase {
|
||||
CustomText {
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
color: root.contentColor
|
||||
font: Config.appearance.font.family.mono // qmllint disable incompatible-type
|
||||
font.family: Config.appearance.font.family.mono // qmllint disable incompatible-type
|
||||
text: Qt.formatDateTime(Time.date, "AP")
|
||||
visible: Config.services.useTwelveHourClock && root.formatParts.timeTokens.length > 0
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import QtQuick
|
||||
import ZShell.Config
|
||||
import qs.Services
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
|
||||
Row {
|
||||
id: root
|
||||
|
||||
property real batHeight: Tokens.padding.smaller * 2
|
||||
property real batWidth: Tokens.padding.larger * 2
|
||||
required property string devState
|
||||
property real nubHeight: Tokens.padding.small
|
||||
property real nubWidth: 2
|
||||
required property real percentage
|
||||
property real radius: Tokens.rounding.smallest / 2
|
||||
|
||||
spacing: 1
|
||||
|
||||
CustomRect {
|
||||
id: track
|
||||
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: Battery.getColors(root.percentage, root.devState).bg
|
||||
height: root.batHeight
|
||||
radius: root.radius
|
||||
width: root.batWidth
|
||||
|
||||
CustomText {
|
||||
color: Battery.getColors(root.percentage, root.devState).fg
|
||||
font.pointSize: Tokens.font.size.larger / 1.5
|
||||
font.weight: 800
|
||||
height: track.height
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: Math.round(root.percentage * 100)
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
width: track.width
|
||||
}
|
||||
|
||||
Item {
|
||||
clip: true
|
||||
width: parent.width * root.percentage
|
||||
|
||||
anchors {
|
||||
bottom: parent.bottom
|
||||
left: parent.left
|
||||
top: parent.top
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
id: fill
|
||||
|
||||
color: Battery.getColors(root.percentage, root.devState).fg
|
||||
height: track.height
|
||||
radius: track.radius
|
||||
width: track.width
|
||||
|
||||
CustomText {
|
||||
id: batteryLabel
|
||||
|
||||
clip: true
|
||||
color: Battery.getColors(root.percentage, root.devState).bg
|
||||
font.pointSize: Tokens.font.size.larger / 1.5
|
||||
font.weight: 800
|
||||
height: track.height
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: Math.round(root.percentage * 100)
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
width: track.width
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
id: nub
|
||||
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
bottomRightRadius: 20
|
||||
color: root.percentage < 0.99 ? track.color : fill.color
|
||||
height: root.nubHeight
|
||||
topRightRadius: 20
|
||||
width: root.nubWidth
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,28 @@ WidgetBase {
|
||||
}
|
||||
}
|
||||
|
||||
DelegateChoice {
|
||||
roleValue: "bluetooth"
|
||||
|
||||
delegate: EntryWrapper {
|
||||
name: "bluetooth"
|
||||
|
||||
BluetoothWidget {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DelegateChoice {
|
||||
roleValue: "network"
|
||||
|
||||
delegate: EntryWrapper {
|
||||
name: "network"
|
||||
|
||||
NetworkWidget {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DelegateChoice {
|
||||
roleValue: "power"
|
||||
|
||||
@@ -112,7 +134,6 @@ WidgetBase {
|
||||
name: "upower"
|
||||
|
||||
UPowerWidget {
|
||||
horizontal: root.horizontal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import ZShell.Config
|
||||
import qs.Services
|
||||
import qs.Components
|
||||
|
||||
MaterialIcon {
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
animate: true
|
||||
color: Colors.palette.m3onSurface // Network.connected ? root.textColor : Colors.palette.m3error
|
||||
fill: 1
|
||||
font.pointSize: Tokens.font.size.larger
|
||||
text: "bluetooth"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import ZShell.Config
|
||||
import qs.Services
|
||||
import qs.Components
|
||||
|
||||
MaterialIcon {
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
animate: true
|
||||
color: Colors.palette.m3onSurface // Network.connected ? root.textColor : Colors.palette.m3error
|
||||
fill: 1
|
||||
font.pointSize: Tokens.font.size.larger
|
||||
text: "android_wifi_4_bar"
|
||||
}
|
||||
@@ -2,16 +2,17 @@ import Quickshell.Services.UPower
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import ZShell.Config
|
||||
import qs.Modules.Bar.Components.Common
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
required property bool horizontal
|
||||
readonly property Item currentItem: batteryIconLoader?.item ?? peripheralIconLoader?.item ?? upowerIconLoader.item
|
||||
|
||||
implicitHeight: Battery.isLaptop ? batteryIconLoader.item.implicitHeight : upowerIconLoader.item.implicitHeight
|
||||
implicitWidth: Battery.isLaptop ? batteryIconLoader.item.implicitWidth : upowerIconLoader.item.implicitWidth
|
||||
implicitHeight: currentItem?.implicitHeight ?? 0
|
||||
implicitWidth: currentItem?.implicitWidth ?? 0
|
||||
|
||||
Behavior on Layout.preferredHeight {
|
||||
Anim {
|
||||
@@ -30,95 +31,36 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: Battery.startDaemon()
|
||||
|
||||
Loader {
|
||||
id: batteryIconLoader
|
||||
|
||||
active: Battery.isLaptop
|
||||
anchors.centerIn: parent
|
||||
|
||||
sourceComponent: Row {
|
||||
id: batteryIcon
|
||||
sourceComponent: BatteryIcon {
|
||||
devState: Battery.deviceStateString
|
||||
percentage: Battery.currentPerc
|
||||
}
|
||||
}
|
||||
|
||||
property real batHeight: 16
|
||||
property real batWidth: 30
|
||||
property real nubHeight: 6
|
||||
property real nubWidth: 2
|
||||
property real radius: Tokens.rounding.smallest / 2
|
||||
Loader {
|
||||
id: peripheralIconLoader
|
||||
|
||||
spacing: 1
|
||||
active: (Battery.lowestPeripheral?.isPresent ?? false) && !batteryIconLoader.active
|
||||
anchors.centerIn: parent
|
||||
|
||||
CustomRect {
|
||||
id: track
|
||||
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: Battery.colors.bg
|
||||
height: batteryIcon.batHeight
|
||||
radius: batteryIcon.radius
|
||||
width: batteryIcon.batWidth
|
||||
|
||||
CustomText {
|
||||
color: Battery.colors.fg
|
||||
font.pointSize: Tokens.font.size.larger / 1.5
|
||||
font.weight: 800
|
||||
height: track.height
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: Math.round(Battery.currentPerc * 100)
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
width: track.width
|
||||
}
|
||||
|
||||
Item {
|
||||
clip: true
|
||||
width: parent.width * Battery.currentPerc
|
||||
|
||||
anchors {
|
||||
bottom: parent.bottom
|
||||
left: parent.left
|
||||
top: parent.top
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
id: fill
|
||||
|
||||
color: Battery.colors.fg
|
||||
height: track.height
|
||||
radius: track.radius
|
||||
width: track.width
|
||||
|
||||
CustomText {
|
||||
id: batteryLabel
|
||||
|
||||
clip: true
|
||||
color: Battery.colors.bg
|
||||
font.pointSize: 7.5
|
||||
font.weight: 800
|
||||
height: track.height
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: Math.round(Battery.currentPerc * 100)
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
width: track.width
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
id: nub
|
||||
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
bottomRightRadius: 20
|
||||
color: Battery.currentPerc < 0.99 ? track.color : fill.color
|
||||
height: batteryIcon.nubHeight
|
||||
topRightRadius: 20
|
||||
width: batteryIcon.nubWidth
|
||||
}
|
||||
sourceComponent: BatteryIcon {
|
||||
devState: Battery.lowestPeripheral?.state ?? ""
|
||||
percentage: Battery.lowestPeripheral?.percentage ?? 0
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: upowerIconLoader
|
||||
|
||||
active: !Battery.isLaptop
|
||||
active: !batteryIconLoader.active && !peripheralIconLoader.active
|
||||
anchors.centerIn: parent
|
||||
|
||||
sourceComponent: MaterialIcon {
|
||||
|
||||
@@ -0,0 +1,385 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import QtQml.Models
|
||||
import Quickshell
|
||||
import Quickshell.Bluetooth
|
||||
import ZShell.Components
|
||||
import ZShell.Config
|
||||
import qs.Services
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
|
||||
CustomClippingRect {
|
||||
id: root
|
||||
|
||||
readonly property list<var> btConnected: Bluetooth.devices.values.filter(d => d.connected)
|
||||
|
||||
implicitHeight: layout.implicitHeight + layout.anchors.margins * 2
|
||||
implicitWidth: 500
|
||||
|
||||
ColumnLayout {
|
||||
id: layout
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.margins: Tokens.padding.larger
|
||||
spacing: Tokens.spacing.extraSmall / 2
|
||||
|
||||
CustomText {
|
||||
Layout.rightMargin: Tokens.padding.extraSmall
|
||||
Layout.topMargin: Tokens.padding.normal
|
||||
font.pointSize: Tokens.font.size.large
|
||||
text: qsTr("Bluetooth")
|
||||
}
|
||||
|
||||
Toggle {
|
||||
checked: Bluetooth.defaultAdapter?.enabled ?? false // qmllint disable unresolved-type
|
||||
first: true
|
||||
subtext: qsTr("Toggle bluetooth device state")
|
||||
text: checked ? qsTr("Enabled") : qsTr("Disabled")
|
||||
|
||||
onToggled: {
|
||||
const adapter = Bluetooth.defaultAdapter; // qmllint disable unresolved-type
|
||||
if (adapter)
|
||||
adapter.enabled = checked;
|
||||
}
|
||||
}
|
||||
|
||||
Toggle {
|
||||
checked: Bluetooth.defaultAdapter?.discovering ?? false // qmllint disable unresolved-type
|
||||
last: root.btConnected.length === 0
|
||||
subtext: qsTr("Enable scanning for new devices")
|
||||
text: qsTr("Discover")
|
||||
|
||||
onToggled: {
|
||||
const adapter = Bluetooth.defaultAdapter; // qmllint disable unresolved-type
|
||||
if (adapter)
|
||||
adapter.discovering = checked;
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: rows
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: contentHeight
|
||||
interactive: false
|
||||
section.property: "connected"
|
||||
spacing: Tokens.spacing.extraSmall / 2
|
||||
|
||||
add: Transition {
|
||||
Anim {
|
||||
from: 0
|
||||
property: "opacity"
|
||||
to: 1
|
||||
}
|
||||
}
|
||||
delegate: DelegateChooser {
|
||||
role: "isDivider"
|
||||
|
||||
DelegateChoice {
|
||||
roleValue: true
|
||||
|
||||
delegate: StatusDivider {
|
||||
}
|
||||
}
|
||||
|
||||
DelegateChoice {
|
||||
delegate: BluetoothItem {
|
||||
list: rows
|
||||
width: rows.width
|
||||
}
|
||||
}
|
||||
}
|
||||
displaced: Transition {
|
||||
Anim {
|
||||
easing.type: Easing.OutCubic
|
||||
property: "y"
|
||||
}
|
||||
}
|
||||
model: ScriptModel {
|
||||
objectProp: "address"
|
||||
values: {
|
||||
const byName = (a, b) => a.name.localeCompare(b.name);
|
||||
return [...[...Bluetooth.devices.values].filter(d => d.connected).sort(byName).slice(0, 5),
|
||||
{
|
||||
isDivider: true
|
||||
},
|
||||
...[...Bluetooth.devices.values].filter(d => !d.connected).sort(byName).slice(0, 5)];
|
||||
}
|
||||
}
|
||||
move: Transition {
|
||||
Anim {
|
||||
easing.type: Easing.OutCubic
|
||||
property: "y"
|
||||
}
|
||||
}
|
||||
remove: Transition {
|
||||
Anim {
|
||||
property: "opacity"
|
||||
to: 0
|
||||
}
|
||||
}
|
||||
section.delegate: Rectangle {
|
||||
required property string section
|
||||
|
||||
color: "transparent"
|
||||
height: childrenRect.height
|
||||
width: ListView.view.width
|
||||
|
||||
CustomText {
|
||||
text: parent.section
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component BluetoothItem: ConnectedRect {
|
||||
id: btItem
|
||||
|
||||
readonly property int connectedCount: root.btConnected.length
|
||||
readonly property bool connecting: Network.connectingNetwork === modelData
|
||||
property int horizontalPadding: Tokens.padding.largeIncreased
|
||||
readonly property bool inConnectedGroup: index < connectedCount
|
||||
required property int index
|
||||
required property ListView list
|
||||
readonly property bool loading: modelData.state === BluetoothDeviceState.Connecting || modelData.state === BluetoothDeviceState.Disconnecting // qmllint disable unresolved-type
|
||||
|
||||
required property BluetoothDevice modelData
|
||||
property int verticalPadding: Tokens.padding.smaller
|
||||
|
||||
first: !inConnectedGroup && index === connectedCount + 1
|
||||
implicitHeight: rowLayout.implicitHeight + verticalPadding * 2
|
||||
last: inConnectedGroup ? index === connectedCount - 1 : index === list.count - 1
|
||||
radius: Tokens.rounding.small
|
||||
|
||||
Timer {
|
||||
interval: 50
|
||||
running: btItem.ListView.delayRemove
|
||||
|
||||
onTriggered: btItem.ListView.delayRemove = false
|
||||
}
|
||||
|
||||
Connections {
|
||||
function onConnectedChanged(): void {
|
||||
if (!btItem.modelData.connected)
|
||||
btItem.ListView.delayRemove = true;
|
||||
}
|
||||
|
||||
function onPairedChanged(): void {
|
||||
if (btItem.modelData.paired)
|
||||
btItem.modelData.connect();
|
||||
}
|
||||
|
||||
target: btItem.modelData
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: rowLayout
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: btItem.horizontalPadding
|
||||
anchors.rightMargin: btItem.horizontalPadding
|
||||
|
||||
Column {
|
||||
id: column
|
||||
|
||||
Layout.fillWidth: true
|
||||
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
Layout.leftMargin: Tokens.spacing.extraSmall
|
||||
Layout.rightMargin: Tokens.spacing.extraSmall
|
||||
elide: Text.ElideRight
|
||||
text: btItem.modelData.name
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: subtext
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
color: Colors.palette.m3outline
|
||||
elide: Text.ElideRight
|
||||
font.pointSize: Tokens.font.size.small
|
||||
text: btItem.modelData.connected ? (btItem.modelData.batteryAvailable ? qsTr("%1 battery left").arg(Math.round(btItem.modelData.battery * 100) + "%") : qsTr("Battery status unknown")) : btItem.modelData.address
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
implicitHeight: icon.height
|
||||
implicitWidth: icon.width
|
||||
|
||||
MaterialIcon {
|
||||
id: icon
|
||||
|
||||
font.pointSize: Tokens.font.size.large
|
||||
opacity: btItem.connecting ? 0 : 1
|
||||
text: btItem.modelData.batteryAvailable ? Icons.getBatteryIcon(btItem.modelData.battery) : "battery_unknown"
|
||||
visible: btItem.modelData.state === BluetoothDeviceState.Connected // qmllint disable unresolved-type
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
active: opacity > 0
|
||||
anchors.fill: parent
|
||||
opacity: btItem.connecting ? 1 : 0
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
sourceComponent: CircularIndicator {
|
||||
bgColor: "transparent"
|
||||
running: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ButtonRow {
|
||||
spacing: Tokens.spacing.small
|
||||
|
||||
IconTextButton {
|
||||
font.pointSize: Tokens.font.size.small
|
||||
icon: btItem.modelData.connected ? "link_off" : btItem.modelData.paired ? "link" : "add_link"
|
||||
text: btItem.modelData.connected ? qsTr("Disconnect") : btItem.modelData.paired ? qsTr("Connect") : qsTr("Pair")
|
||||
|
||||
onClicked: {
|
||||
if (btItem.modelData.connected)
|
||||
btItem.modelData.disconnect();
|
||||
else if (btItem.modelData.paired)
|
||||
btItem.modelData.connect();
|
||||
else if (!btItem.modelData.paired)
|
||||
btItem.modelData.pair();
|
||||
else if (btItem.modelData.pairing)
|
||||
btItem.modelData.cancelPair();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
component ConnectedRect: CustomRect {
|
||||
id: bg
|
||||
|
||||
property bool first
|
||||
property bool last
|
||||
|
||||
bottomLeftRadius: last ? Tokens.rounding.large : Tokens.rounding.extraSmall
|
||||
bottomRightRadius: last ? Tokens.rounding.large : Tokens.rounding.extraSmall
|
||||
color: Colors.tPalette.m3surfaceContainer
|
||||
topLeftRadius: first ? Tokens.rounding.large : Tokens.rounding.extraSmall
|
||||
topRightRadius: first ? Tokens.rounding.large : Tokens.rounding.extraSmall
|
||||
|
||||
Behavior on bottomLeftRadius {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on bottomRightRadius {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on topLeftRadius {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on topRightRadius {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
component StatusDivider: CustomText {
|
||||
bottomPadding: Tokens.spacing.extraSmall
|
||||
color: Colors.palette.m3onSurfaceVariant
|
||||
font.pointSize: Tokens.font.size.smaller
|
||||
text: {
|
||||
const devices = Bluetooth.devices.values; // qmllint disable unresolved-type
|
||||
const connectedCount = devices.filter(d => d.connected).length;
|
||||
let available = qsTr("%1 device%2 available").arg(devices.length - connectedCount).arg(devices.length === 1 ? "" : "s");
|
||||
return available;
|
||||
}
|
||||
topPadding: Tokens.spacing.small
|
||||
}
|
||||
component Toggle: CustomSwitch {
|
||||
id: toggleItem
|
||||
|
||||
readonly property alias bg: bg
|
||||
property alias first: bg.first
|
||||
property alias last: bg.last
|
||||
property string subtext
|
||||
|
||||
Layout.fillWidth: true
|
||||
cLayer: 2
|
||||
horizontalPadding: Tokens.padding.largeIncreased
|
||||
implicitHeight: Math.max(implicitContentHeight, implicitIndicatorHeight) + verticalPadding * 2
|
||||
implicitWidth: implicitContentWidth + implicitIndicatorWidth + horizontalPadding * 2
|
||||
indicator.anchors.right: right
|
||||
indicator.anchors.rightMargin: toggleItem.horizontalPadding
|
||||
indicator.anchors.verticalCenter: verticalCenter
|
||||
verticalPadding: Tokens.padding.normal
|
||||
|
||||
background: ConnectedRect {
|
||||
id: bg
|
||||
|
||||
StateLayer {
|
||||
id: stateLayer
|
||||
|
||||
manualPressOverride: toggleItem.pressed
|
||||
}
|
||||
}
|
||||
contentItem: Item {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: toggleItem.horizontalPadding
|
||||
anchors.right: toggleItem.indicator.left
|
||||
anchors.rightMargin: Tokens.spacing.normal
|
||||
implicitHeight: column.implicitHeight
|
||||
implicitWidth: column.implicitWidth
|
||||
|
||||
Column {
|
||||
id: column
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: 0
|
||||
|
||||
CustomText {
|
||||
id: label
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
elide: Text.ElideRight
|
||||
font: {
|
||||
const f = Qt.font(label.font);
|
||||
f.pointSize = Tokens.font.size.smaller;
|
||||
return f;
|
||||
}
|
||||
text: toggleItem.text
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: subtext
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
color: Colors.palette.m3outline
|
||||
elide: Text.ElideRight
|
||||
font: {
|
||||
const f = Qt.font(subtext.font);
|
||||
f.pointSize = Tokens.font.size.small;
|
||||
return f;
|
||||
}
|
||||
text: toggleItem.subtext
|
||||
visible: toggleItem.subtext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPressed: stateLayer.press(stateLayer.mouseX, stateLayer.mouseY)
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,13 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
Popout {
|
||||
name: "bluetooth"
|
||||
|
||||
sourceComponent: BluetoothPopout {
|
||||
}
|
||||
}
|
||||
|
||||
Popout {
|
||||
name: "updates"
|
||||
|
||||
@@ -96,10 +103,10 @@ Item {
|
||||
readonly property bool shouldBeActive: root.popouts.currentName === name
|
||||
|
||||
active: false
|
||||
// anchors.horizontalCenter: parent.horizontalCenter
|
||||
// anchors.top: parent.top
|
||||
// anchors.topMargin: 5
|
||||
anchors.centerIn: parent
|
||||
anchors.centerIn: opacity === 1 ? undefined : parent
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: opacity === 1 ? parent.top : undefined
|
||||
anchors.topMargin: 5
|
||||
opacity: 0
|
||||
scale: 0.8
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import QtQuick
|
||||
import ZShell.Config
|
||||
import qs.Services
|
||||
import qs.Helpers
|
||||
import qs.Components
|
||||
|
||||
CustomRect {
|
||||
id: root
|
||||
|
||||
readonly property bool closing: PopupManager.closed
|
||||
readonly property url currentPopup: PopupManager.currentPopup
|
||||
property bool shouldBeVisible: loader.status === Loader.Ready
|
||||
|
||||
color: Qt.alpha(Colors.palette.m3shadow, 0.3)
|
||||
opacity: shouldBeVisible && !closing ? 1 : 0
|
||||
visible: opacity > 0
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
|
||||
onVisibleChanged: {
|
||||
if (!visible) {
|
||||
PopupManager.requestClose();
|
||||
PopupManager.currentPopup = "";
|
||||
}
|
||||
}
|
||||
|
||||
CustomMouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
preventStealing: true
|
||||
propagateComposedEvents: false
|
||||
|
||||
onClicked: {
|
||||
const insideItemWidth = mouseX < loader.x + loader.item.width && mouseX > loader.x;
|
||||
const insideItemHeight = mouseY < loader.y + loader.item.height && mouseY > loader.y;
|
||||
if (insideItemHeight && insideItemWidth)
|
||||
return;
|
||||
|
||||
PopupManager.requestClose();
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: loader
|
||||
|
||||
anchors.centerIn: parent
|
||||
|
||||
Connections {
|
||||
function onCurrentPopupChanged(): void {
|
||||
if (PopupManager.currentPopup) {
|
||||
loader.setSource(PopupManager.currentPopup, PopupManager.currentPopupProps);
|
||||
} else {
|
||||
loader.source = null;
|
||||
}
|
||||
}
|
||||
|
||||
target: PopupManager
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
function onNetworkConnected(): void {
|
||||
PopupManager.requestClose();
|
||||
}
|
||||
|
||||
target: Network
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import Quickshell
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import ZShell.Components
|
||||
import ZShell.Config
|
||||
import qs.Services
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
|
||||
CustomClippingRect {
|
||||
id: root
|
||||
|
||||
required property var network
|
||||
|
||||
color: Colors.palette.m3surfaceContainer
|
||||
implicitHeight: layout.implicitHeight + layout.anchors.margins * 2
|
||||
implicitWidth: layout.implicitWidth + layout.anchors.margins * 2
|
||||
radius: Tokens.rounding.large
|
||||
|
||||
ColumnLayout {
|
||||
id: layout
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.margins: Tokens.padding.extraLarge
|
||||
spacing: Tokens.spacing.normal
|
||||
|
||||
MaterialIcon {
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
font.pointSize: Tokens.font.size.extraLarge * 2
|
||||
text: "lock"
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
color: Colors.palette.m3onSurfaceVariant
|
||||
text: qsTr("Connect to %1").arg(root.network.name)
|
||||
}
|
||||
|
||||
CustomTextField {
|
||||
id: passwordField
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: 400
|
||||
echoMode: CustomTextField.Password
|
||||
errorText: qsTr("Failed to connect with given password")
|
||||
isError: Network.failedNetwork
|
||||
leadingIcon: "lock"
|
||||
passwordMaskDelay: 5000
|
||||
placeholderText: qsTr("Input password")
|
||||
}
|
||||
|
||||
ButtonRow {
|
||||
id: buttonRow
|
||||
|
||||
Layout.fillWidth: true
|
||||
spacing: Tokens.spacing.smaller
|
||||
|
||||
IconTextButton {
|
||||
fillWidth: true
|
||||
font.pointSize: Tokens.font.size.normal
|
||||
icon: "close"
|
||||
inactiveColor: Colors.layer(Colors.palette.m3surfaceContainerHighest, 2)
|
||||
inactiveOnColor: Colors.palette.m3onSurfaceVariant
|
||||
isRound: true
|
||||
isToggle: false
|
||||
shapeMorph: true
|
||||
text: "Cancel"
|
||||
|
||||
onClicked: PopupManager.requestClose()
|
||||
}
|
||||
|
||||
IconTextButton {
|
||||
fillWidth: true
|
||||
font.pointSize: Tokens.font.size.normal
|
||||
icon: Network.connectingNetwork ? "" : "check"
|
||||
inactiveColor: Network.connectingNetwork ? Colors.palette.m3primaryContainer : Network.failedNetwork ? Colors.palette.m3error : Colors.palette.m3primary
|
||||
inactiveOnColor: Network.connectingNetwork ? Colors.palette.m3onPrimaryContainer : Network.failedNetwork ? Colors.palette.m3onError : Colors.palette.m3onPrimary
|
||||
isRound: true
|
||||
isToggle: false
|
||||
shapeMorph: true
|
||||
text: Network.connectingNetwork ? "" : "Apply"
|
||||
|
||||
onClicked: Network.requestConnect(root.network, passwordField.text)
|
||||
|
||||
Loader {
|
||||
active: opacity > 0
|
||||
anchors.centerIn: parent
|
||||
opacity: Network.connectingNetwork ? 1 : 0
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
sourceComponent: CircularIndicator {
|
||||
bgColor: "transparent"
|
||||
implicitSize: buttonRow.height - Tokens.padding.normal
|
||||
running: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
pragma Singleton
|
||||
|
||||
import Quickshell
|
||||
import QtQuick
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property bool closed: true
|
||||
property url currentPopup: ""
|
||||
property var currentPopupProps: ({})
|
||||
|
||||
function requestClose(): void {
|
||||
closed = true;
|
||||
}
|
||||
|
||||
function requestOpen(source: url, properties = {}): void {
|
||||
currentPopupProps = properties;
|
||||
currentPopup = source;
|
||||
closed = false;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,362 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Networking
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import qs.Components
|
||||
import Quickshell
|
||||
import ZShell.Components
|
||||
import ZShell.Config
|
||||
import qs.Modules
|
||||
import qs.Helpers as Helpers
|
||||
import qs.Services
|
||||
import qs.Modules.Bar.Popouts.Network
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
|
||||
Item {
|
||||
CustomClippingRect {
|
||||
id: root
|
||||
|
||||
required property var wrapper
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
implicitHeight: networkPopContent.height + networkPopContent.anchors.margins * 2
|
||||
implicitWidth: 500 + 8 * 2
|
||||
radius: (20 - Tokens.padding.small) * Tokens.rounding.scale
|
||||
|
||||
Component.onCompleted: Network.active = true
|
||||
Component.onDestruction: Network.active = false
|
||||
|
||||
ColumnLayout {
|
||||
id: layout
|
||||
id: networkPopContent
|
||||
|
||||
spacing: 8
|
||||
anchors.left: parent.left
|
||||
anchors.margins: Tokens.padding.large
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
spacing: Tokens.spacing.extraSmall / 2
|
||||
|
||||
Repeater {
|
||||
model: Helpers.Network.devices
|
||||
CustomText {
|
||||
Layout.preferredHeight: visible ? implicitHeight : 0
|
||||
Layout.rightMargin: Tokens.padding.extraSmall
|
||||
font.pointSize: Tokens.font.size.large
|
||||
text: qsTr("Wifi")
|
||||
}
|
||||
|
||||
CustomRadioButton {
|
||||
id: network
|
||||
Toggle {
|
||||
Layout.preferredHeight: visible ? implicitHeight : 0
|
||||
checked: Network.wifiEnabled
|
||||
first: true
|
||||
last: Network.connectedNetworks.length === 0
|
||||
subtext: qsTr("Toggle WiFi device state")
|
||||
text: checked ? qsTr("Enabled") : qsTr("Disabled")
|
||||
|
||||
required property NetworkDevice modelData
|
||||
onToggled: Network.setWifi(checked)
|
||||
}
|
||||
|
||||
checked: Helpers.Network.activeDevice?.name === modelData.name
|
||||
text: modelData.description
|
||||
visible: modelData.name !== "lo"
|
||||
ListView {
|
||||
id: rows
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: contentHeight
|
||||
interactive: false
|
||||
section.property: "connected"
|
||||
spacing: Tokens.spacing.extraSmall / 2
|
||||
|
||||
add: Transition {
|
||||
Anim {
|
||||
from: 0
|
||||
property: "opacity"
|
||||
to: 1
|
||||
}
|
||||
}
|
||||
delegate: DelegateChooser {
|
||||
role: "isDivider"
|
||||
|
||||
DelegateChoice {
|
||||
roleValue: true
|
||||
|
||||
delegate: StatusDivider {
|
||||
}
|
||||
}
|
||||
|
||||
DelegateChoice {
|
||||
delegate: NetworkItem {
|
||||
list: rows
|
||||
width: rows.width
|
||||
}
|
||||
}
|
||||
}
|
||||
displaced: Transition {
|
||||
Anim {
|
||||
easing.type: Easing.OutCubic
|
||||
property: "y"
|
||||
}
|
||||
}
|
||||
model: ScriptModel {
|
||||
values: {
|
||||
const byStrengthName = (a, b) => b.signalStrength - a.signalStrength || a.name.localeCompare(b.name);
|
||||
const cNetworks = [...Network.connectedNetworks];
|
||||
const kNetworks = [...Network.knownNetworks];
|
||||
const uNetworks = [...Network.unknownNetworks];
|
||||
|
||||
return [...cNetworks.sort(byStrengthName), ...(kNetworks.length > 0 ? [
|
||||
{
|
||||
isDivider: true,
|
||||
type: "known"
|
||||
},
|
||||
...kNetworks.sort(byStrengthName)] : []), ...(uNetworks.length > 0 ? [
|
||||
{
|
||||
isDivider: true,
|
||||
type: "unknown"
|
||||
},
|
||||
...uNetworks.sort(byStrengthName)] : [])];
|
||||
}
|
||||
}
|
||||
move: Transition {
|
||||
Anim {
|
||||
easing.type: Easing.OutCubic
|
||||
property: "y"
|
||||
}
|
||||
}
|
||||
remove: Transition {
|
||||
Anim {
|
||||
property: "opacity"
|
||||
to: 0
|
||||
}
|
||||
}
|
||||
section.delegate: Rectangle {
|
||||
required property string section
|
||||
|
||||
color: "transparent"
|
||||
height: childrenRect.height
|
||||
width: ListView.view.width
|
||||
|
||||
CustomText {
|
||||
text: parent.section
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NetworkOverlay {
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
||||
component ConnectedRect: CustomRect {
|
||||
id: bg
|
||||
|
||||
property bool first
|
||||
property bool last
|
||||
|
||||
bottomLeftRadius: last ? Tokens.rounding.large : Tokens.rounding.extraSmall
|
||||
bottomRightRadius: last ? Tokens.rounding.large : Tokens.rounding.extraSmall
|
||||
color: Colors.tPalette.m3surfaceContainer
|
||||
topLeftRadius: first ? Tokens.rounding.large : Tokens.rounding.extraSmall
|
||||
topRightRadius: first ? Tokens.rounding.large : Tokens.rounding.extraSmall
|
||||
}
|
||||
component NetworkItem: ConnectedRect {
|
||||
id: networkItem
|
||||
|
||||
readonly property int connectedCount: Network.connectedNetworks.length
|
||||
readonly property bool connecting: Network.connectingNetwork === modelData
|
||||
property int horizontalPadding: Tokens.padding.largeIncreased
|
||||
readonly property bool inConnectedGroup: index < connectedCount
|
||||
// sectioning first / last item in list reminder
|
||||
// if index === network.connectedNetworks.length - 1
|
||||
// if index === network.connectedNetworks.length - 1 + network.knownNetworks.length - 2
|
||||
// if index === network.connectedNetworks.length - 1 + network.knownNetworks.length
|
||||
// list.model.values.length - 1
|
||||
required property int index
|
||||
readonly property bool isSecure: Network.isSecure(modelData.security)
|
||||
required property ListView list
|
||||
required property var modelData
|
||||
property int verticalPadding: Tokens.padding.smaller
|
||||
|
||||
Layout.fillWidth: true
|
||||
first: !inConnectedGroup && index === connectedCount + 1
|
||||
implicitHeight: rowLayout.implicitHeight + verticalPadding * 2
|
||||
last: inConnectedGroup ? index === connectedCount - 1 : index === list.count - 1
|
||||
radius: Tokens.rounding.small
|
||||
|
||||
RowLayout {
|
||||
id: rowLayout
|
||||
|
||||
Layout.preferredHeight: visible ? rowLayout.implicitHeight + Tokens.padding.smaller * 2 : 0
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: networkItem.horizontalPadding
|
||||
anchors.rightMargin: networkItem.horizontalPadding
|
||||
|
||||
Column {
|
||||
id: column
|
||||
|
||||
Layout.fillWidth: true
|
||||
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
Layout.leftMargin: Tokens.spacing.extraSmall
|
||||
Layout.rightMargin: Tokens.spacing.extraSmall
|
||||
color: networkItem.modelData.active ? Colors.palette.m3primary : Colors.palette.m3onSurface
|
||||
elide: Text.ElideRight
|
||||
text: networkItem.modelData.name
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: subtext
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
color: Colors.palette.m3outline
|
||||
elide: Text.ElideRight
|
||||
font.pointSize: Tokens.font.size.small
|
||||
text: networkItem.modelData.connected ? qsTr("Connected: %1 strength").arg(Math.round(networkItem.modelData.signalStrength * 100) + "%") : qsTr("%1 strength").arg(Math.round(networkItem.modelData.signalStrength * 100) + "%")
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
implicitHeight: icon.height
|
||||
implicitWidth: icon.width
|
||||
|
||||
MaterialIcon {
|
||||
id: icon
|
||||
|
||||
color: networkItem.modelData.active ? Colors.palette.m3primary : Colors.palette.m3onSurfaceVariant
|
||||
font.pointSize: Tokens.font.size.large
|
||||
opacity: networkItem.connecting ? 0 : 1
|
||||
text: Icons.getNetworkIcon(networkItem.modelData.signalStrength * 100, networkItem.isSecure)
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
active: opacity > 0
|
||||
anchors.fill: parent
|
||||
opacity: networkItem.connecting ? 1 : 0
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
sourceComponent: CircularIndicator {
|
||||
bgColor: "transparent"
|
||||
running: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StateLayer {
|
||||
color: networkItem.modelData.active ? Colors.palette.m3onPrimary : Colors.palette.m3onSurface
|
||||
|
||||
onClicked: {
|
||||
if (networkItem.isSecure && !networkItem.known) {
|
||||
PopupManager.requestOpen(Qt.resolvedUrl("Network/PSKOverlay.qml"), {
|
||||
network: networkItem.modelData
|
||||
});
|
||||
} else {
|
||||
Network.requestConnect(networkItem.modelData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
component StatusDivider: CustomText {
|
||||
required property var modelData
|
||||
|
||||
bottomPadding: Tokens.spacing.extraSmall
|
||||
color: Colors.palette.m3onSurfaceVariant
|
||||
font.pointSize: Tokens.font.size.smaller
|
||||
text: {
|
||||
if (modelData.type === "known") {
|
||||
const count = Network.knownNetworks.filter(n => !n.connected).length;
|
||||
|
||||
return qsTr("%1 known network%2").arg(count).arg(count === 1 ? "" : "s");
|
||||
}
|
||||
|
||||
if (modelData.type === "unknown") {
|
||||
const count = Network.unknownNetworks.filter(n => !n.connected).length;
|
||||
|
||||
return qsTr("%1 network%2 available").arg(count).arg(count === 1 ? "" : "s");
|
||||
}
|
||||
|
||||
return qsTr("object unknown");
|
||||
}
|
||||
topPadding: Tokens.spacing.small
|
||||
}
|
||||
component Toggle: CustomSwitch {
|
||||
id: toggleItem
|
||||
|
||||
readonly property alias bg: bg
|
||||
property alias first: bg.first
|
||||
property alias last: bg.last
|
||||
property string subtext
|
||||
|
||||
Layout.fillWidth: true
|
||||
cLayer: 2
|
||||
horizontalPadding: Tokens.padding.largeIncreased
|
||||
implicitHeight: Math.max(implicitContentHeight, implicitIndicatorHeight) + verticalPadding * 2
|
||||
implicitWidth: implicitContentWidth + implicitIndicatorWidth + horizontalPadding * 2
|
||||
indicator.anchors.right: right
|
||||
indicator.anchors.rightMargin: toggleItem.horizontalPadding
|
||||
indicator.anchors.verticalCenter: verticalCenter
|
||||
verticalPadding: Tokens.padding.normal
|
||||
|
||||
background: ConnectedRect {
|
||||
id: bg
|
||||
|
||||
StateLayer {
|
||||
id: stateLayer
|
||||
|
||||
manualPressOverride: toggleItem.pressed
|
||||
}
|
||||
}
|
||||
contentItem: Item {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: toggleItem.horizontalPadding
|
||||
anchors.right: toggleItem.indicator.left
|
||||
anchors.rightMargin: Tokens.spacing.normal
|
||||
implicitHeight: column.implicitHeight
|
||||
implicitWidth: column.implicitWidth
|
||||
|
||||
Column {
|
||||
id: column
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: 0
|
||||
|
||||
CustomText {
|
||||
id: label
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
elide: Text.ElideRight
|
||||
font: {
|
||||
const f = Qt.font(label.font);
|
||||
f.pointSize = Tokens.font.size.smaller;
|
||||
return f;
|
||||
}
|
||||
text: toggleItem.text
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: subtext
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
color: Colors.palette.m3outline
|
||||
elide: Text.ElideRight
|
||||
font: {
|
||||
const f = Qt.font(subtext.font);
|
||||
f.pointSize = Tokens.font.size.small;
|
||||
return f;
|
||||
}
|
||||
text: toggleItem.subtext
|
||||
visible: toggleItem.subtext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPressed: stateLayer.press(stateLayer.mouseX, stateLayer.mouseY)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell.Services.UPower
|
||||
import ZShell.Config
|
||||
import qs.Modules.Bar.Components.Common
|
||||
import qs.Helpers
|
||||
import qs.Components
|
||||
import qs.Services
|
||||
@@ -22,6 +24,31 @@ Column {
|
||||
}
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: Battery.allPeripherals
|
||||
|
||||
RowLayout {
|
||||
id: layout
|
||||
|
||||
required property var modelData
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: Tokens.padding.normal
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: Tokens.padding.normal
|
||||
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
text: layout.modelData.model
|
||||
}
|
||||
|
||||
BatteryIcon {
|
||||
devState: layout.modelData.state
|
||||
percentage: layout.modelData.percentage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomText {
|
||||
function formatSeconds(s: int, fallback: string): string {
|
||||
const day = Math.floor(s / 86400);
|
||||
@@ -75,7 +102,7 @@ Column {
|
||||
CustomText {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: Colors.palette.m3onError
|
||||
font.family: Appearance.font.family.mono
|
||||
font.family: Config.appearance.font.family.mono
|
||||
text: qsTr("Performance Degraded")
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +78,6 @@ CustomClippingRect {
|
||||
required property var modelData
|
||||
readonly property list<string> sections: modelData.update.split(" ")
|
||||
|
||||
// anchors.left: parent.left
|
||||
// anchors.right: parent.right
|
||||
color: Colors.tPalette.m3surfaceContainer
|
||||
implicitHeight: root.itemHeight
|
||||
implicitWidth: 600
|
||||
|
||||
@@ -54,7 +54,7 @@ Item {
|
||||
Comp {
|
||||
id: content
|
||||
|
||||
anchors.centerIn: parent
|
||||
anchors.fill: parent
|
||||
shouldBeActive: root.hasCurrent
|
||||
|
||||
sourceComponent: Content {
|
||||
|
||||
@@ -41,7 +41,7 @@ Item {
|
||||
Item {
|
||||
id: view
|
||||
|
||||
readonly property int currentIndex: root.state.currentTab
|
||||
readonly property int currentIndex: root.dashState?.currentTab
|
||||
readonly property Item currentItem: row.children[currentIndex]
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
+140
-147
@@ -1,10 +1,12 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Services.Mpris
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Shapes
|
||||
import QtQuick.Effects
|
||||
import ZShell.Components
|
||||
import ZShell.Services
|
||||
import ZShell.Config
|
||||
import qs.Daemons
|
||||
@@ -14,7 +16,7 @@ import qs.Services
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
readonly property bool hasUnknownLength: (Players.active?.length ?? 0) > 2147483647
|
||||
property real playerProgress: {
|
||||
const active = Players.active;
|
||||
return active?.length ? (active.position % active.length) / active.length : 0;
|
||||
@@ -23,7 +25,19 @@ Item {
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
implicitHeight: cover.height + rowHeight * 2
|
||||
implicitHeight: layout.implicitHeight
|
||||
function lengthStr(length: int): string {
|
||||
if (length < 0)
|
||||
return "-1:-1";
|
||||
|
||||
const hours = Math.floor(length / 3600);
|
||||
const mins = Math.floor((length % 3600) / 60);
|
||||
const secs = Math.floor(length % 60).toString().padStart(2, "0");
|
||||
|
||||
if (hours > 0)
|
||||
return `${hours}:${mins.toString().padStart(2, "0")}:${secs}`;
|
||||
return `${mins}:${secs}`;
|
||||
}
|
||||
|
||||
Behavior on playerProgress {
|
||||
Anim {
|
||||
@@ -32,11 +46,10 @@ Item {
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: Config.dashboard.mediaUpdateInterval
|
||||
repeat: true
|
||||
running: Players.active?.isPlaying ?? false
|
||||
interval: Config.dashboard.mediaUpdateInterval
|
||||
triggeredOnStart: true
|
||||
|
||||
repeat: true
|
||||
onTriggered: Players.active?.positionChanged()
|
||||
}
|
||||
|
||||
@@ -72,7 +85,7 @@ Item {
|
||||
const n = values.length;
|
||||
|
||||
if (n < 2)
|
||||
return "";
|
||||
return "";
|
||||
|
||||
const h = layout.height + shape.strokeWidth / 2;
|
||||
const w = layout.width + shape.strokeWidth;
|
||||
@@ -126,58 +139,11 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
Shape {
|
||||
preferredRendererType: Shape.CurveRenderer
|
||||
|
||||
ShapePath {
|
||||
capStyle: Tokens.rounding.scale === 0 ? ShapePath.SquareCap : ShapePath.RoundCap
|
||||
fillColor: "transparent"
|
||||
strokeColor: Colors.layer(Colors.palette.m3surfaceContainerHigh, 2)
|
||||
strokeWidth: Config.dashboard.sizes.mediaProgressThickness
|
||||
|
||||
Behavior on strokeColor {
|
||||
CAnim {
|
||||
}
|
||||
}
|
||||
|
||||
PathAngleArc {
|
||||
centerX: cover.x + cover.width / 2
|
||||
centerY: cover.y + cover.height / 2
|
||||
radiusX: (cover.width + Config.dashboard.sizes.mediaProgressThickness) / 2 + Tokens.spacing.small
|
||||
radiusY: (cover.height + Config.dashboard.sizes.mediaProgressThickness) / 2 + Tokens.spacing.small
|
||||
startAngle: -90 - Config.dashboard.sizes.mediaProgressSweep / 2
|
||||
sweepAngle: Config.dashboard.sizes.mediaProgressSweep
|
||||
}
|
||||
}
|
||||
|
||||
ShapePath {
|
||||
capStyle: Tokens.rounding.scale === 0 ? ShapePath.SquareCap : ShapePath.RoundCap
|
||||
fillColor: "transparent"
|
||||
strokeColor: Colors.palette.m3primary
|
||||
strokeWidth: Config.dashboard.sizes.mediaProgressThickness
|
||||
|
||||
Behavior on strokeColor {
|
||||
CAnim {
|
||||
}
|
||||
}
|
||||
|
||||
PathAngleArc {
|
||||
centerX: cover.x + cover.width / 2
|
||||
centerY: cover.y + cover.height / 2
|
||||
radiusX: (cover.width + Config.dashboard.sizes.mediaProgressThickness) / 2 + Tokens.spacing.small
|
||||
radiusY: (cover.height + Config.dashboard.sizes.mediaProgressThickness) / 2 + Tokens.spacing.small
|
||||
startAngle: -90 - Config.dashboard.sizes.mediaProgressSweep / 2
|
||||
sweepAngle: Config.dashboard.sizes.mediaProgressSweep * root.playerProgress
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: layout
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
implicitHeight: root.implicitHeight
|
||||
|
||||
CustomClippingRect {
|
||||
id: cover
|
||||
@@ -211,147 +177,174 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
CustomRect {
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.leftMargin: Tokens.spacing.large
|
||||
Layout.rightMargin: Tokens.spacing.large
|
||||
Layout.preferredHeight: childrenRect.height
|
||||
|
||||
spacing: Tokens.spacing.normal
|
||||
|
||||
MarqueeText {
|
||||
id: title
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: parent.top
|
||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
|
||||
color: Colors.palette.m3primary
|
||||
font.pointSize: Tokens.font.size.normal
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
pauseMs: 4000
|
||||
text: (Players.active?.trackTitle ?? qsTr("No media")) || qsTr("Unknown title")
|
||||
width: parent.width - Tokens.padding.large * 4
|
||||
implicitWidth: parent.width - Tokens.padding.large * 4
|
||||
}
|
||||
|
||||
MarqueeText {
|
||||
id: album
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: title.bottom
|
||||
anchors.topMargin: Tokens.spacing.small
|
||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
|
||||
color: Colors.palette.m3outline
|
||||
font.pointSize: Tokens.font.size.small
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
pauseMs: 4000
|
||||
text: (Players.active?.trackAlbum ?? qsTr("No media")) || qsTr("Unknown album")
|
||||
width: parent.width - Tokens.padding.large * 4
|
||||
implicitWidth: parent.width - Tokens.padding.large * 4
|
||||
}
|
||||
|
||||
MarqueeText {
|
||||
id: artist
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: album.bottom
|
||||
anchors.topMargin: Tokens.spacing.small
|
||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
|
||||
color: Colors.palette.m3secondary
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
pauseMs: 4000
|
||||
text: (Players.active?.trackArtist ?? qsTr("No media")) || qsTr("Unknown artist")
|
||||
width: parent.width - Tokens.padding.large * 4
|
||||
implicitWidth: parent.width - Tokens.padding.large * 4
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: controls
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: artist.bottom
|
||||
anchors.topMargin: Tokens.spacing.smaller
|
||||
id: positionSliderLayout
|
||||
Layout.topMargin: Tokens.spacing.extraLargeIncreased
|
||||
Layout.fillWidth: true
|
||||
spacing: Tokens.spacing.small
|
||||
|
||||
Control {
|
||||
function onClicked(): void {
|
||||
Players.active?.previous();
|
||||
}
|
||||
TextMetrics {
|
||||
id: timeMetrics
|
||||
|
||||
canUse: Players.active?.canGoPrevious ?? false
|
||||
text: Players.active ? root.lengthStr(Math.max(Players.active.position, root.hasUnknownLength ? 0 : Players.active.length)).replace(/[1-9]/g, "0") : "00:00"
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: positionLabel
|
||||
|
||||
Layout.preferredWidth: timeMetrics.width
|
||||
text: root.lengthStr(Players.active?.position ?? -1)
|
||||
color: Colors.palette.m3onSurfaceVariant
|
||||
font: timeMetrics.font
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
|
||||
CustomSlider {
|
||||
id: positionSlider
|
||||
|
||||
Layout.fillWidth: true
|
||||
value: Players.active ? Players.active.position / (Players.active.length || 1) : 0
|
||||
enabled: (Players.active?.canSeek ?? false) && !root.hasUnknownLength
|
||||
wavy: true
|
||||
animateWave: Players.active?.isPlaying ?? false
|
||||
waveFrequency: 5
|
||||
waveDuration: 2000
|
||||
interactionOnMove: false
|
||||
onInteraction: value => {
|
||||
const active = Players.active;
|
||||
if (active?.canSeek && active?.positionSupported)
|
||||
active.position = value * active.length;
|
||||
}
|
||||
Binding {
|
||||
target: positionLabel
|
||||
property: "text"
|
||||
value: root.lengthStr(positionSlider.pos * (Players.active?.length ?? 0))
|
||||
when: positionSlider.dragging
|
||||
}
|
||||
}
|
||||
|
||||
CustomText {
|
||||
Layout.preferredWidth: timeMetrics.width
|
||||
text: root.hasUnknownLength ? "--:--" : root.lengthStr(Players.active?.length ?? -1)
|
||||
color: Colors.palette.m3onSurfaceVariant
|
||||
font: timeMetrics.font
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
}
|
||||
ButtonRow {
|
||||
Layout.topMargin: Tokens.spacing.largeIncreased
|
||||
Layout.fillWidth: true
|
||||
spacing: Tokens.spacing.extraSmall
|
||||
Layout.leftMargin: positionSliderLayout.implicitWidth / 4
|
||||
Layout.rightMargin: positionSliderLayout.implicitWidth / 4
|
||||
|
||||
IconButton {
|
||||
type: IconButton.Tonal
|
||||
icon: "shuffle"
|
||||
isRound: true
|
||||
shapeMorph: true
|
||||
checked: Players.active?.shuffle ?? false
|
||||
enabled: Players.active?.shuffleSupported
|
||||
onClicked: Players.active.shuffle = !Players.active?.shuffle
|
||||
implicitWidth: Math.round(implicitHeight * 0.9)
|
||||
}
|
||||
|
||||
IconButton {
|
||||
id: previousBtn
|
||||
|
||||
type: IconButton.Tonal
|
||||
icon: "skip_previous"
|
||||
isRound: true
|
||||
shapeMorph: true
|
||||
enabled: Players.active?.canGoPrevious
|
||||
onClicked: Players.active?.previous()
|
||||
}
|
||||
|
||||
Control {
|
||||
function onClicked(): void {
|
||||
Players.active?.togglePlaying();
|
||||
}
|
||||
IconButton {
|
||||
id: playPauseBtn
|
||||
|
||||
canUse: Players.active?.canTogglePlaying ?? false
|
||||
icon: Players.active?.isPlaying ? "pause" : "play_arrow"
|
||||
isRound: true
|
||||
shapeMorph: true
|
||||
fillWidth: true
|
||||
checked: Players.active?.isPlaying ?? false
|
||||
enabled: Players.active?.canTogglePlaying
|
||||
onClicked: Players.active?.togglePlaying()
|
||||
}
|
||||
|
||||
Control {
|
||||
function onClicked(): void {
|
||||
Players.active?.next();
|
||||
}
|
||||
IconButton {
|
||||
id: nextBtn
|
||||
|
||||
canUse: Players.active?.canGoNext ?? false
|
||||
type: IconButton.Tonal
|
||||
icon: "skip_next"
|
||||
isRound: true
|
||||
shapeMorph: true
|
||||
enabled: Players.active?.canGoNext
|
||||
onClicked: Players.active?.next()
|
||||
}
|
||||
|
||||
IconButton {
|
||||
type: IconButton.Tonal
|
||||
icon: Players.active?.loopState === MprisLoopState.Track ? "repeat_one" : "repeat"
|
||||
isRound: true
|
||||
shapeMorph: true
|
||||
checked: Players.active?.loopState === MprisLoopState.Track || Players.active?.loopState === MprisLoopState.Playlist
|
||||
enabled: Players.active?.loopSupported
|
||||
onClicked: {
|
||||
const state = Players.active.loopState;
|
||||
if (state === MprisLoopState.None)
|
||||
Players.active.loopState = MprisLoopState.Track;
|
||||
else if (state === MprisLoopState.Track)
|
||||
Players.active.loopState = MprisLoopState.Playlist;
|
||||
else
|
||||
Players.active.loopState = MprisLoopState.None;
|
||||
}
|
||||
implicitWidth: Math.round(implicitHeight * 0.9)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component Control: CustomRect {
|
||||
id: control
|
||||
|
||||
required property bool canUse
|
||||
required property string icon
|
||||
property int level: 1
|
||||
property string set_color: "Secondary"
|
||||
|
||||
function onClicked(): void {
|
||||
}
|
||||
|
||||
Layout.preferredWidth: implicitWidth + (controlState.pressed ? Tokens.padding.normal * 2 : 0)
|
||||
color: canUse ? Colors.palette[`m3${set_color.toLowerCase()}`] : Colors.palette[`m3${set_color.toLowerCase()}Container`]
|
||||
implicitHeight: implicitWidth
|
||||
implicitWidth: Math.max(icon.implicitHeight, icon.implicitHeight) + Tokens.padding.small
|
||||
radius: Tokens.rounding.full
|
||||
|
||||
Behavior on Layout.preferredWidth {
|
||||
Anim {
|
||||
duration: Tokens.anim.durations.expressiveFastSpatial
|
||||
easing.bezierCurve: Tokens.anim.curves.expressiveFastSpatial
|
||||
}
|
||||
}
|
||||
Behavior on radius {
|
||||
Anim {
|
||||
duration: Tokens.anim.durations.expressiveFastSpatial
|
||||
easing.bezierCurve: Tokens.anim.curves.expressiveFastSpatial
|
||||
}
|
||||
}
|
||||
|
||||
Elevation {
|
||||
anchors.fill: parent
|
||||
level: controlState.containsMouse && !controlState.pressed ? control.level + 1 : control.level
|
||||
radius: parent.radius
|
||||
z: -1
|
||||
}
|
||||
|
||||
StateLayer {
|
||||
id: controlState
|
||||
|
||||
color: control.canUse ? Colors.palette[`m3on${control.set_color}`] : Colors.palette[`m3on${control.set_color}Container`]
|
||||
enabled: control.canUse
|
||||
|
||||
onClicked: {
|
||||
control.onClicked();
|
||||
}
|
||||
// radius: Tokens.rounding.full
|
||||
}
|
||||
|
||||
MaterialIcon {
|
||||
id: icon
|
||||
|
||||
anchors.centerIn: parent
|
||||
anchors.verticalCenterOffset: font.pointSize * 0.05
|
||||
animate: true
|
||||
color: control.canUse ? Colors.palette[`m3on${control.set_color}`] : Colors.palette[`m3on${control.set_color}Container`]
|
||||
fill: control.canUse ? 1 : 0
|
||||
font.pointSize: Tokens.font.size.large
|
||||
text: control.icon
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ Item {
|
||||
property real offsetScale: shouldBeActive ? 0 : 1
|
||||
required property var panels
|
||||
required property ShellScreen screen
|
||||
readonly property bool shouldBeActive: visibilities.dock && Config.dock.enable
|
||||
readonly property bool shouldBeActive: visibilities.dock && Config.dock.enabled
|
||||
required property PersistentProperties visibilities
|
||||
|
||||
anchors.bottomMargin: (-implicitHeight - 5) * offsetScale
|
||||
|
||||
@@ -1,28 +1,36 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import Quickshell
|
||||
import QtQuick
|
||||
import qs.Modules.Launcher.Services
|
||||
import qs.Modules.Launcher.Items
|
||||
import qs.Components
|
||||
import Quickshell
|
||||
import ZShell.Config
|
||||
import qs.Components
|
||||
import qs.Services
|
||||
import qs.Modules.Launcher.Items
|
||||
import qs.Modules.Launcher.Services
|
||||
|
||||
CustomListView {
|
||||
id: root
|
||||
|
||||
readonly property string displayState: stateForText(displayText)
|
||||
property string displayText
|
||||
readonly property string requestedState: stateForText(search.text)
|
||||
required property SearchBar search
|
||||
required property PersistentProperties visibilities
|
||||
|
||||
highlightFollowsCurrentItem: false
|
||||
highlightRangeMode: ListView.ApplyRange
|
||||
implicitHeight: (Config.launcher.sizes.itemHeight + spacing) * Math.min(Config.launcher.maxAppsShown, count) - spacing
|
||||
orientation: Qt.Vertical
|
||||
preferredHighlightBegin: 0
|
||||
preferredHighlightEnd: height
|
||||
spacing: Tokens.spacing.small
|
||||
state: {
|
||||
const text = search.text;
|
||||
function resultsForText(text: string): var {
|
||||
switch (stateForText(text)) {
|
||||
case "actions":
|
||||
return Actions.query(text);
|
||||
case "calc":
|
||||
return [0];
|
||||
case "variant":
|
||||
return SchemeVariants.query(text);
|
||||
default:
|
||||
return Apps.search(text);
|
||||
}
|
||||
}
|
||||
|
||||
function stateForText(text: string): string {
|
||||
const prefix = Config.launcher.actionPrefix;
|
||||
if (text.startsWith(prefix)) {
|
||||
for (const action of ["calc", "scheme", "variant"])
|
||||
@@ -34,6 +42,20 @@ CustomListView {
|
||||
|
||||
return "apps";
|
||||
}
|
||||
|
||||
function syncDisplayText(): void {
|
||||
if (visibilities.launcher && requestedState === displayState)
|
||||
displayText = search.text;
|
||||
}
|
||||
|
||||
highlightFollowsCurrentItem: false
|
||||
highlightRangeMode: ListView.ApplyRange
|
||||
implicitHeight: (Config.launcher.sizes.itemHeight + spacing) * Math.min(Config.launcher.maxAppsShown, count) - spacing
|
||||
orientation: Qt.Vertical
|
||||
preferredHighlightBegin: 0
|
||||
preferredHighlightEnd: height
|
||||
spacing: Tokens.spacing.small
|
||||
state: visibilities.launcher ? requestedState : displayState
|
||||
verticalLayoutDirection: ListView.BottomToTop
|
||||
|
||||
CustomScrollBar.vertical: CustomScrollBar {
|
||||
@@ -44,19 +66,21 @@ CustomListView {
|
||||
|
||||
Anim {
|
||||
from: 0
|
||||
properties: "opacity,scale"
|
||||
property: "opacity"
|
||||
to: 1
|
||||
type: Anim.DefaultEffects
|
||||
}
|
||||
}
|
||||
addDisplaced: Transition {
|
||||
Anim {
|
||||
duration: Tokens.anim.durations.small
|
||||
property: "y"
|
||||
type: Anim.StandardSmall
|
||||
}
|
||||
|
||||
Anim {
|
||||
properties: "opacity,scale"
|
||||
property: "opacity"
|
||||
to: 1
|
||||
type: Anim.DefaultEffects
|
||||
}
|
||||
}
|
||||
displaced: Transition {
|
||||
@@ -65,8 +89,9 @@ CustomListView {
|
||||
}
|
||||
|
||||
Anim {
|
||||
properties: "opacity,scale"
|
||||
property: "opacity"
|
||||
to: 1
|
||||
type: Anim.DefaultEffects
|
||||
}
|
||||
}
|
||||
highlight: CustomRect {
|
||||
@@ -85,7 +110,7 @@ CustomListView {
|
||||
}
|
||||
}
|
||||
model: ScriptModel {
|
||||
id: model
|
||||
values: root.resultsForText(root.displayText)
|
||||
|
||||
onValuesChanged: root.currentIndex = 0
|
||||
}
|
||||
@@ -95,8 +120,9 @@ CustomListView {
|
||||
}
|
||||
|
||||
Anim {
|
||||
properties: "opacity,scale"
|
||||
property: "opacity"
|
||||
to: 1
|
||||
type: Anim.DefaultEffects
|
||||
}
|
||||
}
|
||||
remove: Transition {
|
||||
@@ -104,8 +130,9 @@ CustomListView {
|
||||
|
||||
Anim {
|
||||
from: 1
|
||||
properties: "opacity,scale"
|
||||
property: "opacity"
|
||||
to: 0
|
||||
type: Anim.DefaultEffects
|
||||
}
|
||||
}
|
||||
states: [
|
||||
@@ -113,7 +140,6 @@ CustomListView {
|
||||
name: "apps"
|
||||
|
||||
PropertyChanges {
|
||||
model.values: Apps.search(search.text)
|
||||
root.delegate: appItem
|
||||
}
|
||||
},
|
||||
@@ -121,7 +147,6 @@ CustomListView {
|
||||
name: "actions"
|
||||
|
||||
PropertyChanges {
|
||||
model.values: Actions.query(search.text)
|
||||
root.delegate: actionItem
|
||||
}
|
||||
},
|
||||
@@ -129,7 +154,6 @@ CustomListView {
|
||||
name: "calc"
|
||||
|
||||
PropertyChanges {
|
||||
model.values: [0]
|
||||
root.delegate: calcItem
|
||||
}
|
||||
},
|
||||
@@ -137,7 +161,6 @@ CustomListView {
|
||||
name: "variant"
|
||||
|
||||
PropertyChanges {
|
||||
model.values: SchemeVariants.query(search.text)
|
||||
root.delegate: variantItem
|
||||
}
|
||||
}
|
||||
@@ -147,7 +170,7 @@ CustomListView {
|
||||
ParallelAnimation {
|
||||
Anim {
|
||||
duration: Tokens.anim.durations.small
|
||||
easing.bezierCurve: Tokens.anim.curves.expressiveEffects
|
||||
easing.bezierCurve: Tokens.anim.curves.standardAccel
|
||||
from: 1
|
||||
property: "opacity"
|
||||
target: root
|
||||
@@ -156,7 +179,7 @@ CustomListView {
|
||||
|
||||
Anim {
|
||||
duration: Tokens.anim.durations.small
|
||||
easing.bezierCurve: Tokens.anim.curves.expressiveEffects
|
||||
easing.bezierCurve: Tokens.anim.curves.standardAccel
|
||||
from: 1
|
||||
property: "scale"
|
||||
target: root
|
||||
@@ -165,14 +188,24 @@ CustomListView {
|
||||
}
|
||||
|
||||
PropertyAction {
|
||||
properties: "values,delegate"
|
||||
targets: [model, root]
|
||||
property: "delegate"
|
||||
target: root
|
||||
value: null
|
||||
}
|
||||
|
||||
ScriptAction {
|
||||
script: root.displayText = root.search.text
|
||||
}
|
||||
|
||||
PropertyAction {
|
||||
property: "delegate"
|
||||
target: root
|
||||
}
|
||||
|
||||
ParallelAnimation {
|
||||
Anim {
|
||||
duration: Tokens.anim.durations.small
|
||||
easing.bezierCurve: Tokens.anim.curves.expressiveEffects
|
||||
easing.bezierCurve: Tokens.anim.curves.standardDecel
|
||||
from: 0
|
||||
property: "opacity"
|
||||
target: root
|
||||
@@ -181,7 +214,7 @@ CustomListView {
|
||||
|
||||
Anim {
|
||||
duration: Tokens.anim.durations.small
|
||||
easing.bezierCurve: Tokens.anim.curves.expressiveEffects
|
||||
easing.bezierCurve: Tokens.anim.curves.standardDecel
|
||||
from: 0.9
|
||||
property: "scale"
|
||||
target: root
|
||||
@@ -197,6 +230,8 @@ CustomListView {
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: displayText = search.text
|
||||
|
||||
Component {
|
||||
id: appItem
|
||||
|
||||
@@ -228,4 +263,20 @@ CustomListView {
|
||||
list: root
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
function onTextChanged() {
|
||||
root.syncDisplayText();
|
||||
}
|
||||
|
||||
target: root.search
|
||||
}
|
||||
|
||||
Connections {
|
||||
function onLauncherChanged() {
|
||||
root.syncDisplayText();
|
||||
}
|
||||
|
||||
target: root.visibilities
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
import Quickshell
|
||||
import QtQuick
|
||||
import ZShell.Components
|
||||
import ZShell.Config
|
||||
import qs.Modules.Launcher.Items
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
|
||||
CarouselView {
|
||||
id: root
|
||||
|
||||
required property var panels
|
||||
readonly property var screen: QsWindow.window?.screen
|
||||
required property SearchBar search
|
||||
readonly property var values: Wallpapers.query(root.search.text.split(" ").slice(1).join(" "))
|
||||
required property var visibilities
|
||||
|
||||
currentIndex: {
|
||||
const idx = Wallpapers.list.findIndex(w => w.path === Wallpapers.actualCurrent);
|
||||
return idx >= 0 ? idx : 0;
|
||||
}
|
||||
delegateProperties: ({
|
||||
visibilities: root.visibilities
|
||||
})
|
||||
focalWidth: Config.launcher.sizes.wallpaperWidth
|
||||
glideDuration: 250
|
||||
glideEasingType: Easing.OutCubic
|
||||
implicitHeight: tileHeight + Tokens.spacing.small / 2 + Tokens.padding.large + Tokens.padding.normal
|
||||
itemSpacing: Tokens.spacing.small
|
||||
maxWidth: {
|
||||
if (!screen)
|
||||
return 0;
|
||||
const barMargins = Config.bar.border * 2;
|
||||
let margins = Math.round(screen.width / 6);
|
||||
if (visibilities.utilities || visibilities.sidebar)
|
||||
margins = Config.sidebar.sizes.width;
|
||||
return screen.width - (barMargins + margins) * 2 - Config.bar.rounding * 4;
|
||||
}
|
||||
minEdgeWidth: 56
|
||||
model: values
|
||||
tileHeight: focalWidth / 16 * 9
|
||||
|
||||
delegate: Component {
|
||||
WallpaperTile {
|
||||
}
|
||||
}
|
||||
|
||||
Component.onDestruction: Wallpapers.stopPreview()
|
||||
onCurrentItemChanged: {
|
||||
if (currentItem)
|
||||
Wallpapers.preview(currentItem.modelData.path);
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ Item {
|
||||
if (currentItem) {
|
||||
if (list.showWallpapers) {
|
||||
if (Colors.scheme === "dynamic" && currentItem.modelData.path !== Wallpapers.actualCurrent)
|
||||
Wallpapers.previewColourLock = true;
|
||||
Wallpapers.previewColorLock = true;
|
||||
Wallpapers.setWallpaper(currentItem.modelData.path);
|
||||
root.visibilities.launcher = false;
|
||||
} else if (text.startsWith(Config.launcher.actionPrefix)) {
|
||||
|
||||
@@ -110,9 +110,9 @@ Item {
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: parent.top
|
||||
width: root.implicitWidth
|
||||
|
||||
sourceComponent: WallpaperList {
|
||||
content: root.content
|
||||
sourceComponent: CarouselView {
|
||||
panels: root.panels
|
||||
search: root.search
|
||||
visibilities: root.visibilities
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
import ZShell.Models
|
||||
import Quickshell
|
||||
import QtQuick
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
import ZShell.Config
|
||||
import qs.Modules
|
||||
import qs.Services
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
required property FileSystemEntry modelData
|
||||
required property PersistentProperties visibilities
|
||||
|
||||
implicitHeight: image.height + label.height + Tokens.spacing.small / 2 + Tokens.padding.large + Tokens.padding.normal
|
||||
implicitWidth: image.width + Tokens.padding.larger * 2
|
||||
opacity: 0
|
||||
scale: 0.5
|
||||
z: PathView.z ?? 0
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
Behavior on scale {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
scale = Qt.binding(() => PathView.isCurrentItem ? 1 : PathView.onPath ? 0.8 : 0);
|
||||
opacity = Qt.binding(() => PathView.onPath ? 1 : 0);
|
||||
}
|
||||
|
||||
StateLayer {
|
||||
radius: Tokens.rounding.normal
|
||||
|
||||
onClicked: {
|
||||
Wallpapers.setWallpaper(root.modelData.path);
|
||||
root.visibilities.launcher = false;
|
||||
}
|
||||
}
|
||||
|
||||
Elevation {
|
||||
anchors.fill: image
|
||||
level: 4
|
||||
opacity: root.PathView.isCurrentItem ? 1 : 0
|
||||
radius: image.radius
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CustomClippingRect {
|
||||
id: image
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
color: Colors.tPalette.m3surfaceContainer
|
||||
implicitHeight: implicitWidth / 16 * 9
|
||||
implicitWidth: Config.launcher.sizes.wallpaperWidth
|
||||
radius: Tokens.rounding.small
|
||||
y: Tokens.padding.large
|
||||
|
||||
MaterialIcon {
|
||||
anchors.centerIn: parent
|
||||
color: Colors.tPalette.m3outline
|
||||
font.pointSize: Tokens.font.size.extraLarge * 2
|
||||
font.weight: 600
|
||||
text: "image"
|
||||
}
|
||||
|
||||
CachingImage {
|
||||
anchors.fill: parent
|
||||
cache: true
|
||||
path: root.modelData.path
|
||||
smooth: !root.PathView.view.moving
|
||||
}
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: label
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: image.bottom
|
||||
anchors.topMargin: Tokens.spacing.small / 2
|
||||
elide: Text.ElideRight
|
||||
font.pointSize: Tokens.font.size.normal
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
renderType: Text.QtRendering
|
||||
text: root.modelData.relativePath
|
||||
width: image.width - Tokens.padding.normal * 2
|
||||
}
|
||||
}
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
import Quickshell
|
||||
import QtQuick
|
||||
import ZShell.Config
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
import qs.Services
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
required property bool isCurrent
|
||||
required property var modelData // FileSystemEntry-like {path, relativePath}
|
||||
required property real tileHeight
|
||||
required property real tileWidth
|
||||
required property PersistentProperties visibilities
|
||||
|
||||
signal requestActivate
|
||||
|
||||
implicitHeight: tileHeight + Tokens.padding.large * 2
|
||||
implicitWidth: tileWidth
|
||||
|
||||
CustomClippingRect {
|
||||
id: image
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
color: Colors.tPalette.m3surfaceContainer
|
||||
implicitHeight: root.tileHeight
|
||||
implicitWidth: root.tileWidth
|
||||
radius: Tokens.rounding.small
|
||||
y: Tokens.padding.large
|
||||
|
||||
MaterialIcon {
|
||||
anchors.centerIn: parent
|
||||
color: Colors.tPalette.m3outline
|
||||
font.pointSize: Tokens.font.size.extraLarge * 2
|
||||
font.weight: 600
|
||||
text: "image"
|
||||
}
|
||||
|
||||
CachingImage {
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: parent.top
|
||||
cache: true
|
||||
fillMode: Image.PreserveAspectCrop
|
||||
height: root.tileHeight
|
||||
path: root.modelData ? root.modelData.path : ""
|
||||
smooth: root.isCurrent
|
||||
sourceSize.height: root.tileHeight
|
||||
sourceSize.width: root.tileHeight * (16 / 9)
|
||||
width: root.tileHeight * (16 / 9)
|
||||
}
|
||||
|
||||
StateLayer {
|
||||
onClicked: root.requestActivate()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import Quickshell
|
||||
import QtQuick
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
import ZShell.Config
|
||||
import qs.Modules.Launcher.Items
|
||||
|
||||
PathView {
|
||||
id: root
|
||||
|
||||
required property var content
|
||||
readonly property int itemWidth: Config.launcher.sizes.wallpaperWidth * 0.9 + Tokens.padding.larger * 2
|
||||
readonly property int numItems: {
|
||||
const screen = QsWindow.window?.screen;
|
||||
if (!screen)
|
||||
return 0;
|
||||
|
||||
// Screen width - 4x outer rounding - 2x max side thickness (cause centered)
|
||||
const barMargins = panels.bar.implicitWidth;
|
||||
let outerMargins = 0;
|
||||
if ((visibilities.utilities || visibilities.sidebar) && panels.utilities.implicitWidth > outerMargins)
|
||||
outerMargins = panels.utilities.implicitWidth;
|
||||
const maxWidth = screen.width - Config.bar.rounding * 4 - (barMargins + outerMargins) * 2;
|
||||
|
||||
if (maxWidth <= 0)
|
||||
return 0;
|
||||
|
||||
const maxItemsOnScreen = Math.floor(maxWidth / itemWidth);
|
||||
const visible = Math.min(maxItemsOnScreen, Config.launcher.maxWallpapers, scriptModel.values.length);
|
||||
|
||||
if (visible === 2)
|
||||
return 1;
|
||||
if (visible > 1 && visible % 2 === 0)
|
||||
return visible - 1;
|
||||
return visible;
|
||||
}
|
||||
required property var panels
|
||||
required property SearchBar search
|
||||
required property var visibilities
|
||||
|
||||
cacheItemCount: 4
|
||||
highlightRangeMode: PathView.StrictlyEnforceRange
|
||||
implicitWidth: Math.min(numItems, count) * itemWidth
|
||||
pathItemCount: numItems
|
||||
preferredHighlightBegin: 0.5
|
||||
preferredHighlightEnd: 0.5
|
||||
snapMode: PathView.SnapToItem
|
||||
|
||||
delegate: WallpaperItem {
|
||||
visibilities: root.visibilities
|
||||
}
|
||||
model: ScriptModel {
|
||||
id: scriptModel
|
||||
|
||||
readonly property string search: root.search.text.split(" ").slice(1).join(" ")
|
||||
|
||||
values: Wallpapers.query(search)
|
||||
|
||||
onValuesChanged: root.currentIndex = search ? 0 : values.findIndex(w => w.path === Wallpapers.actualCurrent)
|
||||
}
|
||||
path: Path {
|
||||
startY: root.height / 2
|
||||
|
||||
PathAttribute {
|
||||
name: "z"
|
||||
value: 0
|
||||
}
|
||||
|
||||
PathLine {
|
||||
relativeY: 0
|
||||
x: root.width / 2
|
||||
}
|
||||
|
||||
PathAttribute {
|
||||
name: "z"
|
||||
value: 1
|
||||
}
|
||||
|
||||
PathLine {
|
||||
relativeY: 0
|
||||
x: root.width
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: currentIndex = Wallpapers.list.findIndex(w => w.path === Wallpapers.actualCurrent)
|
||||
Component.onDestruction: Wallpapers.stopPreview()
|
||||
onCurrentItemChanged: {
|
||||
if (currentItem)
|
||||
Wallpapers.preview(currentItem.modelData.path);
|
||||
}
|
||||
}
|
||||
@@ -464,11 +464,7 @@ CustomRect {
|
||||
|
||||
enabled: root.expanded
|
||||
fillWidth: true
|
||||
font: {
|
||||
const f = Qt.font(font);
|
||||
f.pointSize = Tokens.font.size.small;
|
||||
return f;
|
||||
}
|
||||
font.pointSize: Tokens.font.size.small
|
||||
implicitWidth: label.implicitWidth
|
||||
inactiveColor: root.modelData.urgency === NotificationUrgency.Critical ? Colors.palette.m3secondary : Colors.layer(Colors.palette.m3surfaceContainerHighest, 2)
|
||||
inactiveOnColor: root.modelData.urgency === NotificationUrgency.Critical ? Colors.palette.m3onSecondary : Colors.palette.m3onSurfaceVariant
|
||||
|
||||
@@ -2,8 +2,8 @@ pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import qs.Components
|
||||
import ZShell.Config
|
||||
import qs.Components
|
||||
import qs.Modules.Settings.Common
|
||||
import qs.Modules.Settings.Pages
|
||||
import qs.Modules.Settings.Pages.Wallpaper
|
||||
@@ -45,7 +45,11 @@ QtObject {
|
||||
|
||||
// Connectivity
|
||||
Component {
|
||||
PlaceholderComp {
|
||||
StackPage {
|
||||
Component {
|
||||
NetworkPage {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Component {
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import ZShell.Config
|
||||
import qs.Modules.Settings.Common
|
||||
import qs.Modules.Bar.Popouts.Network
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
import qs.Services
|
||||
|
||||
PageBase {
|
||||
id: root
|
||||
|
||||
title: qsTr("Network")
|
||||
|
||||
ColumnLayout {
|
||||
id: networkContent
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: parent.top
|
||||
spacing: Tokens.spacing.extraSmall / 2
|
||||
width: root.cappedWidth
|
||||
|
||||
Toggle {
|
||||
Layout.preferredHeight: visible ? implicitHeight : 0
|
||||
checked: Network.wifiEnabled
|
||||
first: true
|
||||
last: connected.count === 0
|
||||
subtext: qsTr("Toggle WiFi device state")
|
||||
text: checked ? qsTr("Enabled") : qsTr("Disabled")
|
||||
|
||||
onToggled: Network.setWifi(checked)
|
||||
}
|
||||
|
||||
Repeater {
|
||||
id: connected
|
||||
|
||||
visible: Network.connectedNetworks.length > 0
|
||||
|
||||
model: ScriptModel {
|
||||
values: [...Network.connectedNetworks].sort((a, b) => {
|
||||
return b.signalStrength - a.signalStrength;
|
||||
})
|
||||
}
|
||||
|
||||
NetworkItem {
|
||||
first: false
|
||||
known: true
|
||||
repeater: connected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component NetworkItem: ConnectedRect {
|
||||
id: networkItem
|
||||
|
||||
readonly property bool connecting: Network.connectingNetwork === modelData
|
||||
property int horizontalPadding: Tokens.padding.largeIncreased
|
||||
required property int index
|
||||
readonly property bool isSecure: Network.isSecure(modelData.security)
|
||||
required property bool known
|
||||
required property var modelData
|
||||
required property Repeater repeater
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: visible ? rowLayout.implicitHeight + Tokens.padding.smaller * 2 : 0
|
||||
first: index === 0
|
||||
last: index === (repeater.count - 1)
|
||||
radius: Tokens.rounding.small
|
||||
|
||||
RowLayout {
|
||||
id: rowLayout
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: networkItem.horizontalPadding
|
||||
anchors.rightMargin: networkItem.horizontalPadding
|
||||
|
||||
Column {
|
||||
id: column
|
||||
|
||||
Layout.fillWidth: true
|
||||
|
||||
CustomText {
|
||||
Layout.fillWidth: true
|
||||
Layout.leftMargin: Tokens.spacing.extraSmall
|
||||
Layout.rightMargin: Tokens.spacing.extraSmall
|
||||
color: networkItem.modelData.active ? Colors.palette.m3primary : Colors.palette.m3onSurface
|
||||
elide: Text.ElideRight
|
||||
text: networkItem.modelData.name
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: subtext
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
color: Colors.palette.m3outline
|
||||
elide: Text.ElideRight
|
||||
font.pointSize: Tokens.font.size.small
|
||||
text: qsTr("%1 strength").arg(Math.round(networkItem.modelData.signalStrength * 100) + "%")
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
implicitHeight: icon.height
|
||||
implicitWidth: icon.width
|
||||
|
||||
MaterialIcon {
|
||||
id: icon
|
||||
|
||||
color: networkItem.modelData.active ? Colors.palette.m3primary : Colors.palette.m3onSurfaceVariant
|
||||
font.pointSize: Tokens.font.size.large
|
||||
opacity: networkItem.connecting ? 0 : 1
|
||||
text: Icons.getNetworkIcon(networkItem.modelData.signalStrength * 100, networkItem.isSecure)
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
active: opacity > 0
|
||||
anchors.fill: parent
|
||||
opacity: networkItem.connecting ? 1 : 0
|
||||
|
||||
Behavior on opacity {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
sourceComponent: CircularIndicator {
|
||||
bgColor: "transparent"
|
||||
running: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StateLayer {
|
||||
color: networkItem.modelData.active ? Colors.palette.m3onPrimary : Colors.palette.m3onSurface
|
||||
|
||||
onClicked: {
|
||||
if (networkItem.isSecure && !networkItem.known) {
|
||||
PopupManager.requestOpen(Qt.resolvedUrl("Network/PSKOverlay.qml"), {
|
||||
network: networkItem.modelData
|
||||
});
|
||||
} else {
|
||||
Network.requestConnect(networkItem.modelData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
component Spacer: Item {
|
||||
id: spacer
|
||||
|
||||
required property Repeater repeater
|
||||
|
||||
Layout.preferredHeight: repeater.count > 0 ? Tokens.spacing.extraSmall : 0
|
||||
}
|
||||
component Toggle: CustomSwitch {
|
||||
id: toggleItem
|
||||
|
||||
readonly property alias bg: bg
|
||||
property alias first: bg.first
|
||||
property alias last: bg.last
|
||||
property string subtext
|
||||
|
||||
Layout.fillWidth: true
|
||||
cLayer: 2
|
||||
horizontalPadding: Tokens.padding.largeIncreased
|
||||
implicitHeight: Math.max(implicitContentHeight, implicitIndicatorHeight) + verticalPadding * 2
|
||||
implicitWidth: implicitContentWidth + implicitIndicatorWidth + horizontalPadding * 2
|
||||
indicator.anchors.right: right
|
||||
indicator.anchors.rightMargin: toggleItem.horizontalPadding
|
||||
indicator.anchors.verticalCenter: verticalCenter
|
||||
verticalPadding: Tokens.padding.normal
|
||||
|
||||
background: ConnectedRect {
|
||||
id: bg
|
||||
|
||||
StateLayer {
|
||||
id: stateLayer
|
||||
|
||||
manualPressOverride: toggleItem.pressed
|
||||
}
|
||||
}
|
||||
contentItem: Item {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: toggleItem.horizontalPadding
|
||||
anchors.right: toggleItem.indicator.left
|
||||
anchors.rightMargin: Tokens.spacing.normal
|
||||
implicitHeight: column.implicitHeight
|
||||
implicitWidth: column.implicitWidth
|
||||
|
||||
Column {
|
||||
id: column
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: 0
|
||||
|
||||
CustomText {
|
||||
id: label
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
elide: Text.ElideRight
|
||||
font: {
|
||||
const f = Qt.font(label.font);
|
||||
f.pointSize = Tokens.font.size.smaller;
|
||||
return f;
|
||||
}
|
||||
text: toggleItem.text
|
||||
}
|
||||
|
||||
CustomText {
|
||||
id: subtext
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
color: Colors.palette.m3outline
|
||||
elide: Text.ElideRight
|
||||
font: {
|
||||
const f = Qt.font(subtext.font);
|
||||
f.pointSize = Tokens.font.size.small;
|
||||
return f;
|
||||
}
|
||||
text: toggleItem.subtext
|
||||
visible: toggleItem.subtext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPressed: stateLayer.press(stateLayer.mouseX, stateLayer.mouseY)
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,9 @@ PageBase {
|
||||
readonly property var builtinIcons: ({
|
||||
audio: qsTr("Speakers"),
|
||||
microphone: qsTr("Microphone"),
|
||||
power: qsTr("Battery")
|
||||
power: qsTr("Battery"),
|
||||
network: qsTr("Network"),
|
||||
bluetooth: qsTr("Bluetooth")
|
||||
})
|
||||
|
||||
isSubPage: true
|
||||
@@ -91,5 +93,15 @@ PageBase {
|
||||
|
||||
onToggled: Config.bar.popouts.statusIcons = checked
|
||||
}
|
||||
|
||||
ToggleRow {
|
||||
checked: Config.bar.popouts.network
|
||||
last: true
|
||||
settingAnchor: "bar-status-network-popout"
|
||||
subtext: qsTr("Show a details popout when hovering the network icon")
|
||||
text: qsTr("Network popout on hover")
|
||||
|
||||
onToggled: Config.bar.popouts.network = checked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ PageBase {
|
||||
|
||||
SelectRow {
|
||||
active: Config.bar.position === "top" ? menuItems[0] : Config.bar.position === "left" ? menuItems[1] : menuItems[2]
|
||||
last: true
|
||||
settingAnchor: "bar-position"
|
||||
subtext: qsTr("Change which edge the bar appears on")
|
||||
text: qsTr("Position")
|
||||
@@ -61,6 +60,28 @@ PageBase {
|
||||
onSelected: item => Config.bar.position = item.value
|
||||
}
|
||||
|
||||
ToggleRow {
|
||||
checked: Config.bar.fullscreenReveal
|
||||
settingAnchor: "bar-fullscreen-reveal"
|
||||
subtext: qsTr("Hover top edge to show bar in fullscreen")
|
||||
text: qsTr("Reveal on edge")
|
||||
|
||||
onToggled: Config.bar.fullscreenReveal = checked
|
||||
}
|
||||
|
||||
SpinRow {
|
||||
from: 0
|
||||
last: true
|
||||
settingAnchor: "bar-reveal-delay"
|
||||
stepSize: 100
|
||||
subtext: qsTr("The delay before bar is revealed when cursor is at edge")
|
||||
text: qsTr("Reveal delay")
|
||||
to: 2000
|
||||
value: Config.bar.revealDelay
|
||||
|
||||
onMoved: v => Config.bar.revealDelay = v
|
||||
}
|
||||
|
||||
// Components
|
||||
SectionHeader {
|
||||
text: qsTr("Components")
|
||||
|
||||
@@ -40,40 +40,19 @@ PageBase {
|
||||
id: localWalls
|
||||
|
||||
model: {
|
||||
const walls = Wallpapers.list;
|
||||
const walls = [...Wallpapers.list];
|
||||
var baseDir = Paths.wallsdir;
|
||||
const categories = {};
|
||||
const list = [];
|
||||
for (const w of walls) {
|
||||
var parentDir = w.parentDir;
|
||||
if (!parentDir.endsWith("/"))
|
||||
parentDir = parentDir + "/";
|
||||
walls.sort((a, b) => ((a.parentDir === baseDir) - (b.parentDir === baseDir)) || a.name.localeCompare(b.name));
|
||||
while (walls.length < 4)
|
||||
walls.push(null);
|
||||
|
||||
if (!baseDir.endsWith("/"))
|
||||
baseDir = baseDir + "/";
|
||||
|
||||
if (parentDir !== baseDir) {
|
||||
const category = Wallpapers.getCategoryFor(w);
|
||||
if (category && (!(category in categories) || categories[category].name.localeCompare(w.name) > 0))
|
||||
categories[category] = w;
|
||||
} else {
|
||||
list.push(w);
|
||||
}
|
||||
}
|
||||
list.push(...Object.values(categories));
|
||||
list.sort((a, b) => ((a.parentDir === baseDir) - (b.parentDir === baseDir)) || a.name.localeCompare(b.name));
|
||||
while (list.length < 4)
|
||||
list.push(null);
|
||||
|
||||
return list;
|
||||
return walls;
|
||||
}
|
||||
|
||||
WallItem {
|
||||
required property FileSystemEntry modelData
|
||||
|
||||
enabled: modelData
|
||||
|
||||
// Empty placeholders for sizing
|
||||
opacity: modelData ? 1 : 0
|
||||
source: String(modelData?.path ?? "")
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import Quickshell
|
||||
import QtQuick
|
||||
import qs.Components
|
||||
import ZShell.Config
|
||||
import qs.Helpers
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property real offsetScale: shouldBeActive ? 0 : 1
|
||||
required property var panels
|
||||
property string queuedMode: "wallpaper"
|
||||
required property ShellScreen screen
|
||||
readonly property bool shouldBeActive: visibilities.settings
|
||||
required property PersistentProperties visibilities
|
||||
@@ -37,7 +39,7 @@ Item {
|
||||
|
||||
sourceComponent: Content {
|
||||
sState.animatingContainer: content.opacity < 1
|
||||
sState.currentPageIdx: ["wallpaper"][0]
|
||||
sState.currentPageIdx: ["wallpaper"].indexOf(root.queuedMode)
|
||||
sState.screen: root.screen
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,103 +5,46 @@ import Quickshell.Hyprland
|
||||
import QtQuick
|
||||
import qs.Components
|
||||
import qs.Helpers
|
||||
import ZShell.Config
|
||||
import ZShell.Internal
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property bool completed
|
||||
property real cropHeight: displayData?.height ?? 1.0
|
||||
property real cropWidth: displayData?.width ?? 1.0
|
||||
property real cropX: displayData?.x ?? 0.0
|
||||
property real cropY: displayData?.y ?? 0.0
|
||||
property WallpaperImage current
|
||||
readonly property var displayData: Wallpapers.getCrop(screen.name)
|
||||
required property ShellScreen screen
|
||||
property size screenResolution: Qt.size(screen.width * screenScale, screen.height * screenScale)
|
||||
property real screenScale: Hyprland.monitorFor(screen).scale
|
||||
property string source: Wallpapers.current
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
Component.onCompleted: {
|
||||
Hyprland.refreshMonitors();
|
||||
Component.onCompleted: Hyprland.refreshMonitors()
|
||||
|
||||
if (source)
|
||||
Qt.callLater(() => {
|
||||
current = imgComp.createObject(this, {
|
||||
source
|
||||
});
|
||||
completed = true;
|
||||
});
|
||||
}
|
||||
onSourceChanged: {
|
||||
if (!source)
|
||||
current = null;
|
||||
else
|
||||
current = imgComp.createObject(this, {
|
||||
source: source
|
||||
});
|
||||
}
|
||||
WallpaperImage {
|
||||
id: img
|
||||
|
||||
Component {
|
||||
id: imgComp
|
||||
anchors.fill: parent
|
||||
cropHeight: root.displayData?.height ?? 1.0
|
||||
cropWidth: root.displayData?.width ?? 1.0
|
||||
cropX: root.displayData?.x ?? 0.0
|
||||
cropY: root.displayData?.y ?? 0.0
|
||||
fadeDuration: 150
|
||||
screenResolution: root.screenResolution
|
||||
source: Wallpapers.current
|
||||
|
||||
WallpaperImage {
|
||||
id: img
|
||||
|
||||
anchors.fill: parent
|
||||
cropHeight: root.cropHeight
|
||||
cropWidth: root.cropWidth
|
||||
cropX: root.cropX
|
||||
cropY: root.cropY
|
||||
opacity: 0
|
||||
screenResolution: root.screenResolution
|
||||
source: root.source
|
||||
|
||||
Behavior on cropHeight {
|
||||
Anim {
|
||||
id: heightAnim
|
||||
}
|
||||
Behavior on cropHeight {
|
||||
Anim {
|
||||
}
|
||||
Behavior on cropWidth {
|
||||
Anim {
|
||||
id: widthAnim
|
||||
}
|
||||
}
|
||||
Behavior on cropWidth {
|
||||
Anim {
|
||||
}
|
||||
Behavior on cropX {
|
||||
Anim {
|
||||
id: xAnim
|
||||
}
|
||||
}
|
||||
Behavior on cropX {
|
||||
Anim {
|
||||
}
|
||||
Behavior on cropY {
|
||||
Anim {
|
||||
id: yAnim
|
||||
}
|
||||
}
|
||||
Anim on opacity {
|
||||
id: anim
|
||||
|
||||
from: 0
|
||||
running: false
|
||||
to: 1
|
||||
type: Anim.SlowEffects
|
||||
}
|
||||
|
||||
onStatusChanged: {
|
||||
if (status === Image.Ready) {
|
||||
anim.start();
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: destroyTimer
|
||||
|
||||
interval: anim.duration * 2
|
||||
running: root.current !== img && root.current?.status === Image.Ready
|
||||
|
||||
onTriggered: Qt.callLater(() => img.destroy())
|
||||
}
|
||||
Behavior on cropY {
|
||||
Anim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ qml_module(ZShell-components
|
||||
lazylistview.hpp lazylistview.cpp
|
||||
wavyline.hpp wavyline.cpp
|
||||
buttonrow.hpp buttonrow.cpp
|
||||
carouselview.hpp carouselview.cpp
|
||||
LIBRARIES
|
||||
Qt::Quick
|
||||
)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,255 @@
|
||||
#pragma once
|
||||
|
||||
#include <QQmlParserStatus>
|
||||
#include <QElapsedTimer>
|
||||
#include <QEasingCurve>
|
||||
#include <QList>
|
||||
#include <QPointF>
|
||||
#include <QQuickItem>
|
||||
#include <QQmlComponent>
|
||||
#include <QQmlEngine>
|
||||
#include <QVariantAnimation>
|
||||
#include <QVariantList>
|
||||
#include <QVector>
|
||||
#include <qtypes.h>
|
||||
#include <qvectornd.h>
|
||||
|
||||
namespace ZShell::components {
|
||||
|
||||
class CarouselView : public QQuickItem {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
|
||||
Q_PROPERTY(
|
||||
QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY
|
||||
delegateChanged)
|
||||
Q_PROPERTY(QVariantList model READ model WRITE setModel NOTIFY modelChanged)
|
||||
|
||||
Q_PROPERTY(
|
||||
qreal focalWidth READ focalWidth WRITE setFocalWidth NOTIFY
|
||||
focalWidthChanged)
|
||||
Q_PROPERTY(
|
||||
qreal minEdgeWidth READ minEdgeWidth WRITE setMinEdgeWidth NOTIFY
|
||||
minEdgeWidthChanged)
|
||||
Q_PROPERTY(
|
||||
qreal itemSpacing READ itemSpacing WRITE setItemSpacing NOTIFY
|
||||
itemSpacingChanged)
|
||||
Q_PROPERTY(
|
||||
qreal tileHeight READ tileHeight WRITE setTileHeight NOTIFY
|
||||
tileHeightChanged)
|
||||
Q_PROPERTY(
|
||||
qreal maxWidth READ maxWidth WRITE setMaxWidth NOTIFY maxWidthChanged)
|
||||
|
||||
Q_PROPERTY(
|
||||
int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY
|
||||
currentIndexChanged)
|
||||
|
||||
Q_PROPERTY(
|
||||
QQuickItem* currentItem READ currentItem NOTIFY currentItemChanged)
|
||||
|
||||
Q_PROPERTY(
|
||||
int glideDuration READ glideDuration WRITE setGlideDuration NOTIFY
|
||||
glideDurationChanged)
|
||||
Q_PROPERTY(
|
||||
QEasingCurve::Type glideEasingType READ glideEasingType WRITE
|
||||
setGlideEasingType NOTIFY glideEasingTypeChanged)
|
||||
|
||||
Q_PROPERTY(
|
||||
QVariantMap delegateProperties READ delegateProperties WRITE
|
||||
setDelegateProperties NOTIFY delegatePropertiesChanged)
|
||||
|
||||
public:
|
||||
explicit CarouselView(QQuickItem* parent = nullptr);
|
||||
~CarouselView() override;
|
||||
|
||||
QQmlComponent* delegate() const { return m_delegate; }
|
||||
void setDelegate(QQmlComponent* c);
|
||||
|
||||
QVariantList model() const { return m_model; }
|
||||
void setModel(const QVariantList& m);
|
||||
|
||||
qreal focalWidth() const { return m_focalWidth; }
|
||||
void setFocalWidth(qreal v);
|
||||
|
||||
qreal minEdgeWidth() const { return m_minEdgeWidth; }
|
||||
void setMinEdgeWidth(qreal v);
|
||||
|
||||
qreal itemSpacing() const { return m_itemSpacing; }
|
||||
void setItemSpacing(qreal v);
|
||||
|
||||
qreal tileHeight() const { return m_tileHeight; }
|
||||
void setTileHeight(qreal v);
|
||||
|
||||
qreal maxWidth() const { return m_maxWidth; }
|
||||
void setMaxWidth(qreal v);
|
||||
|
||||
int currentIndex() const { return m_currentRealIndex; }
|
||||
void setCurrentIndex(int idx);
|
||||
|
||||
QQuickItem* currentItem() const { return m_currentItem; }
|
||||
|
||||
int glideDuration() const { return m_glideDuration; }
|
||||
void setGlideDuration(int v);
|
||||
|
||||
QEasingCurve::Type glideEasingType() const { return m_glideEasingType; }
|
||||
void setGlideEasingType(QEasingCurve::Type t);
|
||||
|
||||
QVariantMap delegateProperties() const { return m_delegateProperties; }
|
||||
void setDelegateProperties(const QVariantMap& v);
|
||||
|
||||
Q_INVOKABLE void goToIndex(int realIndex);
|
||||
Q_INVOKABLE void incrementCurrentIndex();
|
||||
Q_INVOKABLE void decrementCurrentIndex();
|
||||
|
||||
signals:
|
||||
void delegateChanged();
|
||||
void modelChanged();
|
||||
void focalWidthChanged();
|
||||
void minEdgeWidthChanged();
|
||||
void itemSpacingChanged();
|
||||
void tileHeightChanged();
|
||||
void maxWidthChanged();
|
||||
void currentIndexChanged();
|
||||
void currentItemChanged();
|
||||
void glideDurationChanged();
|
||||
void glideEasingTypeChanged();
|
||||
void delegatePropertiesChanged();
|
||||
|
||||
void activated(int realIndex, QVariant modelData);
|
||||
void previewIndexChanged(int realIndex, QVariant modelData);
|
||||
|
||||
protected:
|
||||
void classBegin() override;
|
||||
void componentComplete() override;
|
||||
bool childMouseEventFilter(QQuickItem* item, QEvent* event) override;
|
||||
void geometryChange(const QRectF& newGeo, const QRectF& oldGeo) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
void mouseUngrabEvent() override;
|
||||
void wheelEvent(QWheelEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void handleDelegateActivate();
|
||||
|
||||
private:
|
||||
struct Arrangement {
|
||||
int n = 0;
|
||||
qreal width = 0;
|
||||
qreal outerSpacing = 0;
|
||||
|
||||
QVector<qreal> sizes;
|
||||
QVector<qreal> centers;
|
||||
|
||||
qreal effectiveExtraWidth = 0;
|
||||
};
|
||||
|
||||
struct Slot {
|
||||
QQuickItem* item = nullptr;
|
||||
int virtualIndex = 0;
|
||||
int realIndex = -1;
|
||||
bool active = false;
|
||||
};
|
||||
|
||||
struct VelocitySample {
|
||||
qint64 t;
|
||||
qreal x;
|
||||
};
|
||||
|
||||
void rebuildArrangement();
|
||||
void relayout();
|
||||
|
||||
Arrangement arrangementForCount(int n) const;
|
||||
|
||||
int layoutCapacityForWidth(qreal width) const;
|
||||
qreal targetWidthForMaxWidth(qreal maxWidth) const;
|
||||
|
||||
void updateSlotContent(Slot& slot, int virtualIndex);
|
||||
|
||||
void positionSlot(const Slot& slot) const;
|
||||
|
||||
void applyPropertiesToItem(QQuickItem* item, int realIndex) const;
|
||||
|
||||
qreal pitch() const { return m_focalWidth + m_itemSpacing; }
|
||||
|
||||
qreal contentXForIndex(qreal index) const;
|
||||
int indexForContentX(qreal x) const;
|
||||
qreal snapTargetX(qreal x) const;
|
||||
|
||||
void snapToNearest();
|
||||
void glideTo(qreal dest);
|
||||
void cancelAnimations();
|
||||
|
||||
qreal keylineSize(int io) const;
|
||||
qreal sampleSize(qreal childLoc) const;
|
||||
qreal continuousIndex() const;
|
||||
|
||||
int realIndexOf(int virtualIndex) const;
|
||||
|
||||
void updateCurrentIndexFromContentX(bool emitPreview);
|
||||
|
||||
void updateCurrentItem();
|
||||
|
||||
void wrapContentIfNeeded();
|
||||
void centerInstantlyOnReal(int realIndex);
|
||||
|
||||
QQuickItem* acquireItem();
|
||||
void releaseAllItems();
|
||||
|
||||
void addVelocitySample(qint64 t, qreal x);
|
||||
qreal sampledVelocity() const;
|
||||
|
||||
void notifyCurrentIndexChanged();
|
||||
void notifyCurrentItemChanged();
|
||||
void notifyPreviewIndexChanged(int realIndex);
|
||||
|
||||
QQmlComponent* m_delegate = nullptr;
|
||||
QVariantList m_model;
|
||||
QVariantMap m_delegateProperties;
|
||||
|
||||
qreal m_focalWidth = 0;
|
||||
qreal m_minEdgeWidth = 56;
|
||||
qreal m_itemSpacing = 8;
|
||||
qreal m_tileHeight = 0;
|
||||
qreal m_maxWidth = 0;
|
||||
|
||||
Arrangement m_arrangement;
|
||||
|
||||
int m_layoutCapacity = 0;
|
||||
|
||||
qreal m_contentX = 0;
|
||||
int m_currentVirtualIndex = 0;
|
||||
int m_currentRealIndex = -1;
|
||||
int m_previewRealIndex = -1;
|
||||
|
||||
QQuickItem* m_currentItem = nullptr;
|
||||
|
||||
int m_centerBlockStart = 0;
|
||||
|
||||
QList<Slot> m_slots;
|
||||
|
||||
int m_glideDuration = 250;
|
||||
QEasingCurve::Type m_glideEasingType = QEasingCurve::OutCubic;
|
||||
QVariantAnimation* m_glideAnim = nullptr;
|
||||
|
||||
bool m_dragging = false;
|
||||
bool m_dragActive = false;
|
||||
|
||||
QPointF m_pressPos;
|
||||
qreal m_pressContentX = 0;
|
||||
|
||||
QElapsedTimer m_dragTimer;
|
||||
|
||||
QVector<VelocitySample> m_velocitySamples;
|
||||
static constexpr qint64 kVelocitySampleWindowMs = 80;
|
||||
|
||||
QVariantAnimation* m_flickAnim = nullptr;
|
||||
|
||||
bool m_completed = false;
|
||||
int m_pendingCurrentIndex = -1;
|
||||
|
||||
bool m_initializedLayout = false;
|
||||
bool m_relayoutQueued = false;
|
||||
};
|
||||
|
||||
} // namespace ZShell::components
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "cachingimagemanager.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QtQuick/qquickwindow.h>
|
||||
#include <qcryptographichash.h>
|
||||
#include <qdir.h>
|
||||
@@ -7,10 +9,27 @@
|
||||
#include <qfuturewatcher.h>
|
||||
#include <qimagereader.h>
|
||||
#include <qpainter.h>
|
||||
#include <qthread.h>
|
||||
#include <qthreadpool.h>
|
||||
#include <qtconcurrentrun.h>
|
||||
|
||||
namespace ZShell::internal {
|
||||
|
||||
namespace {
|
||||
|
||||
QThreadPool* imageIoPool() {
|
||||
static QThreadPool pool;
|
||||
static const bool init = [] {
|
||||
pool.setMaxThreadCount(std::max(2, QThread::idealThreadCount() / 2));
|
||||
return true;
|
||||
}();
|
||||
(void)init;
|
||||
|
||||
return &pool;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
qreal CachingImageManager::effectiveScale() const {
|
||||
if (m_item && m_item->window()) {
|
||||
return m_item->window()->devicePixelRatio();
|
||||
@@ -101,14 +120,13 @@ void CachingImageManager::updateSource() {
|
||||
|
||||
void CachingImageManager::updateSource(const QString& path) {
|
||||
if (path.isEmpty() || path == m_shaPath) {
|
||||
// Path is empty or already calculating sha for path
|
||||
return;
|
||||
}
|
||||
|
||||
m_shaPath = path;
|
||||
|
||||
const auto future =
|
||||
QtConcurrent::run(&CachingImageManager::sha256sum, path);
|
||||
QtConcurrent::run(imageIoPool(), &CachingImageManager::sha256sum, path);
|
||||
|
||||
const auto watcher = new QFutureWatcher<QString>(this);
|
||||
|
||||
@@ -118,7 +136,16 @@ void CachingImageManager::updateSource(const QString& path) {
|
||||
this,
|
||||
[watcher, path, this]() {
|
||||
if (m_path != path) {
|
||||
// Object is destroyed or path has changed, ignore
|
||||
watcher->deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
const QString key = watcher->result();
|
||||
|
||||
if (key.isEmpty()) {
|
||||
if (m_shaPath == path) {
|
||||
m_shaPath = QString();
|
||||
}
|
||||
watcher->deleteLater();
|
||||
return;
|
||||
}
|
||||
@@ -126,19 +153,29 @@ void CachingImageManager::updateSource(const QString& path) {
|
||||
const QSize size = effectiveSize();
|
||||
|
||||
if (!m_item || !size.width() || !size.height()) {
|
||||
if (m_shaPath == path) {
|
||||
m_shaPath = QString();
|
||||
}
|
||||
watcher->deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
const QString fillMode = m_item->property("fillMode").toString();
|
||||
// clang-format off
|
||||
const QString filename = QString("%1@%2x%3-%4.png")
|
||||
.arg(watcher->result()).arg(size.width()).arg(size.height())
|
||||
.arg(fillMode == "PreserveAspectCrop" ? "crop" : fillMode == "PreserveAspectFit" ? "fit" : "stretch");
|
||||
// clang-format on
|
||||
const QString filename =
|
||||
QString("%1@%2x%3-%4.png")
|
||||
.arg(key)
|
||||
.arg(size.width())
|
||||
.arg(size.height())
|
||||
.arg(
|
||||
fillMode == "PreserveAspectCrop" ? "crop"
|
||||
: fillMode == "PreserveAspectFit" ? "fit"
|
||||
: "stretch");
|
||||
|
||||
const QUrl cache = m_cacheDir.resolved(QUrl(filename));
|
||||
if (m_cachePath == cache) {
|
||||
if (m_shaPath == path) {
|
||||
m_shaPath = QString();
|
||||
}
|
||||
watcher->deleteLater();
|
||||
return;
|
||||
}
|
||||
@@ -149,6 +186,9 @@ void CachingImageManager::updateSource(const QString& path) {
|
||||
if (!cache.isLocalFile()) {
|
||||
qWarning() << "CachingImageManager::updateSource: cachePath"
|
||||
<< cache << "is not a local file";
|
||||
if (m_shaPath == path) {
|
||||
m_shaPath = QString();
|
||||
}
|
||||
watcher->deleteLater();
|
||||
return;
|
||||
}
|
||||
@@ -161,7 +201,6 @@ void CachingImageManager::updateSource(const QString& path) {
|
||||
createCache(path, cache.toLocalFile(), fillMode, size);
|
||||
}
|
||||
|
||||
// Clear current running sha if same
|
||||
if (m_shaPath == path) {
|
||||
m_shaPath = QString();
|
||||
}
|
||||
@@ -170,7 +209,6 @@ void CachingImageManager::updateSource(const QString& path) {
|
||||
});
|
||||
|
||||
watcher->setFuture(future);
|
||||
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
}
|
||||
|
||||
QUrl CachingImageManager::cachePath() const {
|
||||
@@ -182,61 +220,105 @@ void CachingImageManager::createCache(
|
||||
const QString& cache,
|
||||
const QString& fillMode,
|
||||
const QSize& size) const {
|
||||
QThreadPool::globalInstance()->start([path, cache, fillMode, size] {
|
||||
QImage image(path);
|
||||
auto* watcher =
|
||||
new QFutureWatcher<bool>(const_cast<CachingImageManager*>(this));
|
||||
|
||||
if (image.isNull()) {
|
||||
qWarning() << "CachingImageManager::createCache: failed to read"
|
||||
<< path;
|
||||
return;
|
||||
}
|
||||
connect(
|
||||
watcher,
|
||||
&QFutureWatcher<bool>::finished,
|
||||
this,
|
||||
[this, watcher, cache, path]() {
|
||||
if (watcher->result() && m_item && m_path == path &&
|
||||
m_cachePath.toLocalFile() == cache) {
|
||||
m_item->setProperty("source", QUrl::fromLocalFile(cache));
|
||||
}
|
||||
|
||||
image.convertTo(QImage::Format_ARGB32);
|
||||
watcher->deleteLater();
|
||||
});
|
||||
|
||||
if (fillMode == "PreserveAspectCrop") {
|
||||
image = image.scaled(
|
||||
size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
||||
} else if (fillMode == "PreserveAspectFit") {
|
||||
image = image.scaled(
|
||||
size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
} else {
|
||||
image = image.scaled(
|
||||
size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
const auto future =
|
||||
QtConcurrent::run(
|
||||
imageIoPool(), [path, cache, fillMode, size]() -> bool {
|
||||
QImageReader reader(path);
|
||||
|
||||
if (fillMode == "PreserveAspectCrop" ||
|
||||
fillMode == "PreserveAspectFit") {
|
||||
QImage canvas(size, QImage::Format_ARGB32);
|
||||
canvas.fill(Qt::transparent);
|
||||
if (reader.supportsOption(QImageIOHandler::ScaledSize)) {
|
||||
const QSize full = reader.size();
|
||||
if (full.isValid() && !full.isEmpty()) {
|
||||
const QSize hint = size * 2;
|
||||
QSize scaled = full;
|
||||
scaled.scale(hint, Qt::KeepAspectRatioByExpanding);
|
||||
scaled = QSize(
|
||||
std::min(scaled.width(), full.width()),
|
||||
std::min(scaled.height(), full.height()));
|
||||
reader.setScaledSize(scaled);
|
||||
}
|
||||
}
|
||||
|
||||
QPainter painter(&canvas);
|
||||
painter.drawImage(
|
||||
(size.width() - image.width()) / 2,
|
||||
(size.height() - image.height()) / 2,
|
||||
image);
|
||||
painter.end();
|
||||
QImage image = reader.read();
|
||||
|
||||
image = canvas;
|
||||
}
|
||||
if (image.isNull()) {
|
||||
qWarning()
|
||||
<< "CachingImageManager::createCache: failed to read"
|
||||
<< path << reader.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString parent = QFileInfo(cache).absolutePath();
|
||||
if (!QDir().mkpath(parent) || !image.save(cache)) {
|
||||
qWarning() << "CachingImageManager::createCache: failed to save to"
|
||||
<< cache;
|
||||
}
|
||||
});
|
||||
image.convertTo(QImage::Format_ARGB32);
|
||||
|
||||
if (fillMode == "PreserveAspectCrop") {
|
||||
image = image.scaled(
|
||||
size,
|
||||
Qt::KeepAspectRatioByExpanding,
|
||||
Qt::SmoothTransformation);
|
||||
} else if (fillMode == "PreserveAspectFit") {
|
||||
image = image.scaled(
|
||||
size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
} else {
|
||||
image = image.scaled(
|
||||
size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
if (fillMode == "PreserveAspectCrop" ||
|
||||
fillMode == "PreserveAspectFit") {
|
||||
QImage canvas(size, QImage::Format_ARGB32);
|
||||
canvas.fill(Qt::transparent);
|
||||
|
||||
QPainter painter(&canvas);
|
||||
painter.drawImage(
|
||||
(size.width() - image.width()) / 2,
|
||||
(size.height() - image.height()) / 2,
|
||||
image);
|
||||
painter.end();
|
||||
|
||||
image = canvas;
|
||||
}
|
||||
|
||||
const QString parent = QFileInfo(cache).absolutePath();
|
||||
if (!QDir().mkpath(parent) || !image.save(cache)) {
|
||||
qWarning()
|
||||
<< "CachingImageManager::createCache: failed to save to"
|
||||
<< cache;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
watcher->setFuture(future);
|
||||
}
|
||||
|
||||
QString CachingImageManager::sha256sum(const QString& path) {
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "CachingImageManager::sha256sum: failed to open" << path;
|
||||
return "";
|
||||
const QFileInfo info(path);
|
||||
|
||||
if (!info.exists() || !info.isFile()) {
|
||||
qWarning() << "CachingImageManager::sha256sum: failed to stat" << path;
|
||||
return QString();
|
||||
}
|
||||
|
||||
QCryptographicHash hash(QCryptographicHash::Sha256);
|
||||
hash.addData(&file);
|
||||
file.close();
|
||||
hash.addData(path.toUtf8());
|
||||
hash.addData(QByteArray::number(info.size()));
|
||||
hash.addData(QByteArray::number(info.lastModified().toMSecsSinceEpoch()));
|
||||
|
||||
return hash.result().toHex();
|
||||
}
|
||||
|
||||
@@ -4,14 +4,31 @@
|
||||
#include <QCryptographicHash>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QImageReader>
|
||||
#include <QtConcurrent>
|
||||
#include <QSGImageNode>
|
||||
#include <QQuickWindow>
|
||||
|
||||
namespace ZShell::internal {
|
||||
|
||||
QThreadPool* WallpaperImage::loadPool() {
|
||||
static QThreadPool* pool = [] {
|
||||
auto* p = new QThreadPool();
|
||||
p->setMaxThreadCount(4);
|
||||
return p;
|
||||
}();
|
||||
return pool;
|
||||
}
|
||||
|
||||
WallpaperImage::WallpaperImage(QQuickItem* parent) : QQuickItem(parent) {
|
||||
setFlag(ItemHasContents, true);
|
||||
|
||||
m_loadDebounceTimer.setSingleShot(true);
|
||||
connect(
|
||||
&m_loadDebounceTimer,
|
||||
&QTimer::timeout,
|
||||
this,
|
||||
&WallpaperImage::beginLoad);
|
||||
|
||||
connect(
|
||||
&m_imageWatcher,
|
||||
&QFutureWatcher<QImage>::finished,
|
||||
@@ -20,12 +37,15 @@ WallpaperImage::WallpaperImage(QQuickItem* parent) : QQuickItem(parent) {
|
||||
}
|
||||
|
||||
WallpaperImage::~WallpaperImage() {
|
||||
m_requestGeneration->fetch_add(1, std::memory_order_relaxed);
|
||||
m_imageWatcher.disconnect();
|
||||
|
||||
if (m_texture) delete m_texture;
|
||||
if (m_previousTexture) delete m_previousTexture;
|
||||
}
|
||||
|
||||
void WallpaperImage::setStatus(const Status s) {
|
||||
if (m_status == s) return;
|
||||
|
||||
m_status = s;
|
||||
emit statusChanged();
|
||||
}
|
||||
@@ -36,14 +56,14 @@ void WallpaperImage::setSource(const QUrl& source) {
|
||||
emit sourceChanged();
|
||||
|
||||
setStatus(Loading);
|
||||
loadImage();
|
||||
m_loadDebounceTimer.start(80);
|
||||
}
|
||||
|
||||
void WallpaperImage::setScreenResolution(const QSize& screenResolution) {
|
||||
if (m_screenResolution == screenResolution) return;
|
||||
m_screenResolution = screenResolution;
|
||||
emit screenResolutionChanged();
|
||||
loadImage();
|
||||
beginLoad();
|
||||
}
|
||||
|
||||
void WallpaperImage::setZoom(qreal zoom) {
|
||||
@@ -53,6 +73,13 @@ void WallpaperImage::setZoom(qreal zoom) {
|
||||
update();
|
||||
}
|
||||
|
||||
void WallpaperImage::setFadeDuration(int ms) {
|
||||
if (ms < 0) ms = 0;
|
||||
if (m_fadeDuration == ms) return;
|
||||
m_fadeDuration = ms;
|
||||
emit fadeDurationChanged();
|
||||
}
|
||||
|
||||
void WallpaperImage::setCropX(qreal x) {
|
||||
if (qFuzzyCompare(m_cropX, x)) return;
|
||||
m_cropX = x;
|
||||
@@ -100,143 +127,227 @@ QString WallpaperImage::getCacheFilePath() const {
|
||||
return cachePath + "/" + hash + ".png";
|
||||
}
|
||||
|
||||
void WallpaperImage::loadImage() {
|
||||
void WallpaperImage::beginLoad() {
|
||||
if (m_source.isEmpty()) {
|
||||
setStatus(Null);
|
||||
return;
|
||||
}
|
||||
|
||||
const quint64 requestId =
|
||||
m_requestGeneration->fetch_add(1, std::memory_order_relaxed) + 1;
|
||||
|
||||
QString cacheFile = getCacheFilePath();
|
||||
QString sourceFile = m_source.isLocalFile() ? m_source.toLocalFile()
|
||||
: m_source.toString();
|
||||
|
||||
if (sourceFile.startsWith("qrc:/")) {
|
||||
sourceFile = sourceFile.mid(3);
|
||||
}
|
||||
if (sourceFile.startsWith("qrc:/")) sourceFile = sourceFile.mid(3);
|
||||
|
||||
QSize targetRes = m_screenResolution;
|
||||
auto generation = m_requestGeneration;
|
||||
|
||||
QFuture<QImage> future = QtConcurrent::run(
|
||||
loadPool(),
|
||||
[sourceFile, cacheFile, targetRes, requestId, generation]() -> QImage {
|
||||
auto stale = [&] {
|
||||
return generation->load(std::memory_order_relaxed) != requestId;
|
||||
};
|
||||
|
||||
if (stale()) return QImage();
|
||||
|
||||
QFuture<QImage> future =
|
||||
QtConcurrent::run([sourceFile, cacheFile, targetRes]() -> QImage {
|
||||
if (!targetRes.isEmpty() && !cacheFile.isEmpty() &&
|
||||
QFileInfo::exists(cacheFile)) {
|
||||
QImage cached(cacheFile);
|
||||
if (!cached.isNull()) return cached;
|
||||
}
|
||||
|
||||
QImage original(sourceFile);
|
||||
if (stale()) return QImage();
|
||||
|
||||
QImage original;
|
||||
QImageReader reader(sourceFile);
|
||||
if (!targetRes.isEmpty() &&
|
||||
reader.supportsOption(QImageIOHandler::Size)) {
|
||||
QSize actual = reader.size();
|
||||
if (actual.isValid() &&
|
||||
(actual.width() > targetRes.width() ||
|
||||
actual.height() > targetRes.height())) {
|
||||
QSize scaledSize =
|
||||
actual.scaled(targetRes, Qt::KeepAspectRatioByExpanding);
|
||||
reader.setScaledSize(scaledSize);
|
||||
}
|
||||
original = reader.read();
|
||||
} else {
|
||||
original = QImage(sourceFile);
|
||||
}
|
||||
if (original.isNull()) return QImage();
|
||||
|
||||
if (targetRes.isEmpty()) {
|
||||
return original;
|
||||
}
|
||||
if (stale()) return QImage();
|
||||
|
||||
if (original.width() > targetRes.width() ||
|
||||
original.height() > targetRes.height()) {
|
||||
QImage scaled = original.scaled(
|
||||
targetRes,
|
||||
Qt::KeepAspectRatioByExpanding,
|
||||
Qt::SmoothTransformation);
|
||||
if (!cacheFile.isEmpty()) scaled.save(cacheFile, "PNG");
|
||||
return scaled;
|
||||
}
|
||||
if (targetRes.isEmpty()) return original;
|
||||
|
||||
if (!cacheFile.isEmpty()) original.save(cacheFile, "PNG");
|
||||
return original;
|
||||
QImage scaled = (original.width() > targetRes.width() ||
|
||||
original.height() > targetRes.height())
|
||||
? original.scaled(
|
||||
targetRes,
|
||||
Qt::KeepAspectRatioByExpanding,
|
||||
Qt::SmoothTransformation)
|
||||
: original;
|
||||
|
||||
if (stale()) return scaled;
|
||||
|
||||
if (!cacheFile.isEmpty()) scaled.save(cacheFile, "PNG");
|
||||
return scaled;
|
||||
});
|
||||
|
||||
m_imageWatcher.setFuture(future);
|
||||
}
|
||||
|
||||
void WallpaperImage::handleImageLoaded() {
|
||||
m_image = m_imageWatcher.result();
|
||||
QImage result = m_imageWatcher.result();
|
||||
if (result.isNull()) {
|
||||
setStatus(Error);
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus(m_image.isNull() ? Error : Ready);
|
||||
|
||||
m_textureDirty = true;
|
||||
m_pendingImage = result;
|
||||
m_hasPending = true;
|
||||
setStatus(Ready);
|
||||
update();
|
||||
}
|
||||
|
||||
QSGNode* WallpaperImage::updatePaintNode(
|
||||
QSGNode* oldNode, UpdatePaintNodeData*) {
|
||||
auto* node = static_cast<QSGImageNode*>(oldNode);
|
||||
QRectF WallpaperImage::computeSourceRect(QSGTexture* texture) const {
|
||||
QSize texSize = texture->textureSize();
|
||||
|
||||
if (m_image.isNull()) {
|
||||
delete node;
|
||||
return nullptr;
|
||||
qreal cW = m_cropWidth / m_zoom;
|
||||
qreal cH = m_cropHeight / m_zoom;
|
||||
|
||||
QRectF reqRect(
|
||||
m_cropX * texSize.width(),
|
||||
m_cropY * texSize.height(),
|
||||
cW * texSize.width(),
|
||||
cH * texSize.height());
|
||||
|
||||
QRectF bounds = boundingRect();
|
||||
if (bounds.isEmpty() || reqRect.isEmpty()) return reqRect;
|
||||
|
||||
qreal targetRatio = bounds.width() / bounds.height();
|
||||
qreal reqRatio = reqRect.width() / reqRect.height();
|
||||
|
||||
QRectF sourceRect = reqRect;
|
||||
|
||||
if (reqRatio > targetRatio) {
|
||||
qreal newWidth = reqRect.height() * targetRatio;
|
||||
qreal xOffset = (reqRect.width() - newWidth) / 2.0;
|
||||
sourceRect.setX(reqRect.x() + xOffset);
|
||||
sourceRect.setWidth(newWidth);
|
||||
} else if (reqRatio < targetRatio) {
|
||||
qreal newHeight = reqRect.width() / targetRatio;
|
||||
qreal yOffset = (reqRect.height() - newHeight) / 2.0;
|
||||
sourceRect.setY(reqRect.y() + yOffset);
|
||||
sourceRect.setHeight(newHeight);
|
||||
}
|
||||
|
||||
if (!node) {
|
||||
node = window()->createImageNode();
|
||||
}
|
||||
return sourceRect;
|
||||
}
|
||||
|
||||
if (m_textureDirty) {
|
||||
if (m_texture) delete m_texture;
|
||||
m_texture = window()->createTextureFromImage(
|
||||
m_image, QQuickWindow::TextureHasAlphaChannel);
|
||||
m_textureDirty = false;
|
||||
}
|
||||
void WallpaperImage::configureImageNode(
|
||||
QSGImageNode* node, QSGTexture* texture) {
|
||||
node->setTexture(texture);
|
||||
node->setRect(boundingRect());
|
||||
node->setFiltering(QSGTexture::Linear);
|
||||
|
||||
if (m_texture) {
|
||||
node->setTexture(m_texture);
|
||||
node->setRect(boundingRect());
|
||||
node->setFiltering(QSGTexture::Linear);
|
||||
|
||||
qreal cW = m_cropWidth / m_zoom;
|
||||
qreal cH = m_cropHeight / m_zoom;
|
||||
|
||||
QRectF reqRect(
|
||||
m_cropX * m_texture->textureSize().width(),
|
||||
m_cropY * m_texture->textureSize().height(),
|
||||
cW * m_texture->textureSize().width(),
|
||||
cH * m_texture->textureSize().height());
|
||||
|
||||
QRectF bounds = boundingRect();
|
||||
if (bounds.isEmpty() || reqRect.isEmpty()) return node;
|
||||
|
||||
qreal targetRatio = bounds.width() / bounds.height();
|
||||
qreal reqRatio = reqRect.width() / reqRect.height();
|
||||
|
||||
QRectF sourceRect = reqRect;
|
||||
|
||||
if (reqRatio > targetRatio) {
|
||||
qreal newWidth = reqRect.height() * targetRatio;
|
||||
qreal xOffset = (reqRect.width() - newWidth) / 2.0;
|
||||
sourceRect.setX(reqRect.x() + xOffset);
|
||||
sourceRect.setWidth(newWidth);
|
||||
} else if (reqRatio < targetRatio) {
|
||||
qreal newHeight = reqRect.width() / targetRatio;
|
||||
qreal yOffset = (reqRect.height() - newHeight) / 2.0;
|
||||
sourceRect.setY(reqRect.y() + yOffset);
|
||||
sourceRect.setHeight(newHeight);
|
||||
}
|
||||
QRectF sourceRect = computeSourceRect(texture);
|
||||
node->setSourceRect(sourceRect);
|
||||
|
||||
if (texture == m_texture) {
|
||||
QSize texSize = texture->textureSize();
|
||||
QRectF normalizedActual(
|
||||
sourceRect.x() / m_texture->textureSize().width(),
|
||||
sourceRect.y() / m_texture->textureSize().height(),
|
||||
sourceRect.width() / m_texture->textureSize().width(),
|
||||
sourceRect.height() / m_texture->textureSize().height());
|
||||
sourceRect.x() / texSize.width(),
|
||||
sourceRect.y() / texSize.height(),
|
||||
sourceRect.width() / texSize.width(),
|
||||
sourceRect.height() / texSize.height());
|
||||
|
||||
bool changed = false;
|
||||
|
||||
auto updateIfChanged = [&](qreal& dst, qreal value) {
|
||||
if (!qFuzzyCompare(dst, value)) {
|
||||
dst = value;
|
||||
changed = true;
|
||||
}
|
||||
};
|
||||
|
||||
updateIfChanged(m_actualCropX, normalizedActual.x());
|
||||
updateIfChanged(m_actualCropY, normalizedActual.y());
|
||||
updateIfChanged(m_actualCropWidth, normalizedActual.width());
|
||||
updateIfChanged(m_actualCropHeight, normalizedActual.height());
|
||||
|
||||
if (changed) emit actualCropChanged();
|
||||
}
|
||||
}
|
||||
|
||||
node->setSourceRect(sourceRect);
|
||||
QSGNode* WallpaperImage::updatePaintNode(
|
||||
QSGNode* oldNode, UpdatePaintNodeData*) {
|
||||
Q_UNUSED(oldNode);
|
||||
|
||||
if (m_hasPending) {
|
||||
if (m_previousTexture) {
|
||||
delete m_previousTexture;
|
||||
m_previousTexture = nullptr;
|
||||
}
|
||||
m_previousTexture = m_texture;
|
||||
m_texture = window()->createTextureFromImage(
|
||||
m_pendingImage, QQuickWindow::TextureHasAlphaChannel);
|
||||
m_pendingImage = QImage();
|
||||
m_hasPending = false;
|
||||
|
||||
if (m_previousTexture && m_fadeDuration > 0) {
|
||||
m_fading = true;
|
||||
m_fadeTimer.restart();
|
||||
} else {
|
||||
if (m_previousTexture) {
|
||||
delete m_previousTexture;
|
||||
m_previousTexture = nullptr;
|
||||
}
|
||||
m_fading = false;
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
if (!m_texture) {
|
||||
return m_rootNode;
|
||||
}
|
||||
|
||||
if (!m_rootNode) {
|
||||
m_rootNode = new QSGNode();
|
||||
|
||||
m_newOpacityNode = new QSGOpacityNode();
|
||||
m_newImageNode = window()->createImageNode();
|
||||
m_newOpacityNode->appendChildNode(m_newImageNode);
|
||||
m_rootNode->appendChildNode(m_newOpacityNode);
|
||||
|
||||
m_oldOpacityNode = new QSGOpacityNode();
|
||||
m_oldImageNode = window()->createImageNode();
|
||||
m_oldOpacityNode->appendChildNode(m_oldImageNode);
|
||||
m_rootNode->appendChildNode(m_oldOpacityNode);
|
||||
}
|
||||
|
||||
configureImageNode(m_newImageNode, m_texture);
|
||||
m_newOpacityNode->setOpacity(1.0);
|
||||
|
||||
if (m_fading && m_previousTexture) {
|
||||
qreal progress =
|
||||
qBound(0.0, qreal(m_fadeTimer.elapsed()) / m_fadeDuration, 1.0);
|
||||
|
||||
configureImageNode(m_oldImageNode, m_previousTexture);
|
||||
m_oldOpacityNode->setOpacity(1.0 - progress);
|
||||
|
||||
if (progress >= 1.0) {
|
||||
m_fading = false;
|
||||
delete m_previousTexture;
|
||||
m_previousTexture = nullptr;
|
||||
m_oldOpacityNode->setOpacity(0.0);
|
||||
} else {
|
||||
update();
|
||||
}
|
||||
} else {
|
||||
m_oldOpacityNode->setOpacity(0.0);
|
||||
}
|
||||
|
||||
return m_rootNode;
|
||||
}
|
||||
|
||||
} // namespace ZShell::internal
|
||||
|
||||
@@ -4,9 +4,15 @@
|
||||
#include <QImage>
|
||||
#include <QUrl>
|
||||
#include <QSGTexture>
|
||||
#include <QSGOpacityNode>
|
||||
#include <QSGImageNode>
|
||||
#include <QFutureWatcher>
|
||||
#include <QElapsedTimer>
|
||||
#include <QThreadPool>
|
||||
#include <QTimer>
|
||||
#include <QtQml/qqml.h>
|
||||
#include <qtmetamacros.h>
|
||||
#include <atomic>
|
||||
|
||||
namespace ZShell::internal {
|
||||
|
||||
@@ -19,6 +25,9 @@ class WallpaperImage : public QQuickItem {
|
||||
NOTIFY screenResolutionChanged)
|
||||
Q_PROPERTY(qreal zoom READ zoom WRITE setZoom NOTIFY zoomChanged)
|
||||
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
|
||||
Q_PROPERTY(
|
||||
int fadeDuration READ fadeDuration WRITE setFadeDuration NOTIFY
|
||||
fadeDurationChanged)
|
||||
|
||||
Q_PROPERTY(qreal actualCropX READ actualCropX NOTIFY actualCropChanged)
|
||||
Q_PROPERTY(qreal actualCropY READ actualCropY NOTIFY actualCropChanged)
|
||||
@@ -54,12 +63,12 @@ class WallpaperImage : public QQuickItem {
|
||||
qreal zoom() const { return m_zoom; }
|
||||
void setZoom(qreal zoom);
|
||||
|
||||
int fadeDuration() const { return m_fadeDuration; }
|
||||
void setFadeDuration(int ms);
|
||||
|
||||
qreal actualCropX() const { return m_actualCropX; }
|
||||
|
||||
qreal actualCropY() const { return m_actualCropY; }
|
||||
|
||||
qreal actualCropWidth() const { return m_actualCropWidth; }
|
||||
|
||||
qreal actualCropHeight() const { return m_actualCropHeight; }
|
||||
|
||||
qreal cropX() const { return m_cropX; }
|
||||
@@ -82,6 +91,7 @@ class WallpaperImage : public QQuickItem {
|
||||
void sourceChanged();
|
||||
void screenResolutionChanged();
|
||||
void zoomChanged();
|
||||
void fadeDurationChanged();
|
||||
void actualCropChanged();
|
||||
void cropXChanged();
|
||||
void cropYChanged();
|
||||
@@ -90,15 +100,18 @@ class WallpaperImage : public QQuickItem {
|
||||
void statusChanged();
|
||||
|
||||
private:
|
||||
void loadImage();
|
||||
void beginLoad();
|
||||
void handleImageLoaded();
|
||||
QString getCacheFilePath() const;
|
||||
void setStatus(const Status s);
|
||||
QRectF computeSourceRect(QSGTexture* texture) const;
|
||||
void configureImageNode(QSGImageNode* node, QSGTexture* texture);
|
||||
|
||||
Status m_status = Null;
|
||||
QUrl m_source;
|
||||
QSize m_screenResolution;
|
||||
qreal m_zoom = 1.0;
|
||||
int m_fadeDuration = 400;
|
||||
|
||||
qreal m_actualCropX = 0.0;
|
||||
qreal m_actualCropY = 0.0;
|
||||
@@ -110,10 +123,25 @@ class WallpaperImage : public QQuickItem {
|
||||
qreal m_cropWidth = 1.0;
|
||||
qreal m_cropHeight = 1.0;
|
||||
|
||||
QImage m_image;
|
||||
QSGTexture* m_texture = nullptr;
|
||||
bool m_textureDirty = false;
|
||||
QTimer m_loadDebounceTimer;
|
||||
QFutureWatcher<QImage> m_imageWatcher;
|
||||
std::shared_ptr<std::atomic<quint64>> m_requestGeneration =
|
||||
std::make_shared<std::atomic<quint64>>(0);
|
||||
static QThreadPool* loadPool();
|
||||
QImage m_pendingImage;
|
||||
bool m_hasPending = false;
|
||||
|
||||
QSGTexture* m_texture = nullptr;
|
||||
QSGTexture* m_previousTexture = nullptr;
|
||||
|
||||
bool m_fading = false;
|
||||
QElapsedTimer m_fadeTimer;
|
||||
|
||||
QSGNode* m_rootNode = nullptr;
|
||||
QSGOpacityNode* m_newOpacityNode = nullptr;
|
||||
QSGOpacityNode* m_oldOpacityNode = nullptr;
|
||||
QSGImageNode* m_newImageNode = nullptr;
|
||||
QSGImageNode* m_oldImageNode = nullptr;
|
||||
};
|
||||
|
||||
} // namespace ZShell::internal
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ Singleton {
|
||||
}
|
||||
|
||||
for (const [name, color] of Object.entries(scheme.colors)) {
|
||||
const propName = name.startsWith("term") ? name : `m3${name}`;
|
||||
const propName = `m3${name}`;
|
||||
if (colors.hasOwnProperty(propName))
|
||||
colors[propName] = `${color}`;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,14 @@ import typer
|
||||
from typer._completion_classes import completion_init
|
||||
from typer._completion_shared import _get_shell_name, install
|
||||
|
||||
from zshell.subcommands import record, scheme, screenshot, shell, wallpaper
|
||||
from zshell.subcommands import (
|
||||
battery,
|
||||
record,
|
||||
scheme,
|
||||
screenshot,
|
||||
shell,
|
||||
wallpaper,
|
||||
)
|
||||
|
||||
app = typer.Typer(name="zshell-cli", add_completion=False)
|
||||
|
||||
@@ -17,6 +24,7 @@ app.add_typer(scheme.app, name="scheme")
|
||||
app.add_typer(screenshot.app, name="screenshot")
|
||||
app.add_typer(wallpaper.app, name="wallpaper")
|
||||
app.add_typer(record.app, name="record")
|
||||
app.add_typer(battery.app, name="battery")
|
||||
|
||||
|
||||
def _completion_installed() -> bool:
|
||||
|
||||
@@ -0,0 +1,819 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import fcntl
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
import struct
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
from collections.abc import Callable
|
||||
from dataclasses import asdict, dataclass
|
||||
from pathlib import Path
|
||||
|
||||
import typer
|
||||
from logitech_receiver import hidpp10, hidpp20
|
||||
from logitech_receiver.common import Battery, BatteryStatus, Notification
|
||||
from logitech_receiver.hidpp10_constants import Registers
|
||||
from logitech_receiver.hidpp20_constants import SupportedFeature
|
||||
|
||||
app = typer.Typer(
|
||||
help="Read live battery status from Logitech HID++ peripherals."
|
||||
)
|
||||
|
||||
logger = logging.getLogger("zshell.battery")
|
||||
|
||||
DEFAULT_OUTPUT = Path.home() / ".cache" / "zshell" / "battery.json"
|
||||
|
||||
_RUNTIME_DIR = Path(
|
||||
os.environ.get("XDG_RUNTIME_DIR") or (Path.home() / ".cache" / "zshell")
|
||||
)
|
||||
DEFAULT_LOCK = _RUNTIME_DIR / "zshell-battery-daemon.lock"
|
||||
|
||||
|
||||
def _acquire_singleton_lock(path: Path) -> int | None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
fd = os.open(path, os.O_CREAT | os.O_RDWR, 0o644)
|
||||
try:
|
||||
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except BlockingIOError:
|
||||
os.close(fd)
|
||||
return None
|
||||
os.ftruncate(fd, 0)
|
||||
os.write(fd, str(os.getpid()).encode())
|
||||
return fd
|
||||
|
||||
|
||||
@dataclass
|
||||
class DeviceBattery:
|
||||
model: str
|
||||
nativePath: str | None
|
||||
serial: str | None
|
||||
type: str | None
|
||||
wired: bool
|
||||
percentage: float | None
|
||||
state: str | None
|
||||
charging: bool
|
||||
isPresent: bool
|
||||
|
||||
|
||||
_SYSFS_POWER_SUPPLY = Path("/sys/class/power_supply")
|
||||
|
||||
|
||||
def _normalize_serial(s: str) -> str:
|
||||
return re.sub(r"[^0-9A-Za-z]", "", s).upper()
|
||||
|
||||
|
||||
def _find_upower_native_path(serial: str | None) -> str | None:
|
||||
if not serial or not _SYSFS_POWER_SUPPLY.is_dir():
|
||||
return None
|
||||
target = _normalize_serial(serial)
|
||||
for entry in _SYSFS_POWER_SUPPLY.glob("hidpp_battery_*"):
|
||||
try:
|
||||
raw = (entry / "serial_number").read_text().strip()
|
||||
except OSError:
|
||||
logger.debug(
|
||||
"couldn't read serial_number under %s", entry, exc_info=True
|
||||
)
|
||||
continue
|
||||
if _normalize_serial(raw) == target:
|
||||
return entry.name
|
||||
return None
|
||||
|
||||
|
||||
def _process_battery_notification(dev, n) -> bool:
|
||||
|
||||
if not getattr(dev, "isDevice", False):
|
||||
return False
|
||||
|
||||
if int(n.sub_id) & 0x80:
|
||||
return False
|
||||
if n.sub_id == Notification.NO_OPERATION:
|
||||
return False
|
||||
|
||||
if getattr(dev, "protocol", None) is not None and dev.protocol < 2.0:
|
||||
if n.sub_id in (Registers.BATTERY_STATUS, Registers.BATTERY_CHARGE):
|
||||
if n.data[-1:] != b"\x00":
|
||||
return False
|
||||
data = bytes([n.address]) + n.data
|
||||
dev.set_battery_info(hidpp10.parse_battery_status(n.sub_id, data))
|
||||
return True
|
||||
return False
|
||||
|
||||
features = getattr(dev, "features", None)
|
||||
if not features:
|
||||
return False
|
||||
|
||||
try:
|
||||
feature = features.get_feature(n.sub_id)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
if feature == SupportedFeature.BATTERY_STATUS:
|
||||
if n.address == 0x00:
|
||||
dev.set_battery_info(hidpp20.decipher_battery_status(n.data)[1])
|
||||
return True
|
||||
return False
|
||||
|
||||
if feature == SupportedFeature.BATTERY_VOLTAGE:
|
||||
if n.address == 0x00:
|
||||
dev.set_battery_info(hidpp20.decipher_battery_voltage(n.data)[1])
|
||||
return True
|
||||
return False
|
||||
|
||||
if feature == SupportedFeature.UNIFIED_BATTERY:
|
||||
if n.address == 0x00:
|
||||
dev.set_battery_info(hidpp20.decipher_battery_unified(n.data)[1])
|
||||
return True
|
||||
return False
|
||||
|
||||
if feature == SupportedFeature.ADC_MEASUREMENT:
|
||||
if n.address == 0x00:
|
||||
result = hidpp20.decipher_adc_measurement(n.data)
|
||||
if result:
|
||||
dev.set_battery_info(result[1])
|
||||
return True
|
||||
return False
|
||||
|
||||
if feature == SupportedFeature.CENTURION_BATTERY_SOC:
|
||||
dev.set_battery_info(hidpp20.decipher_battery_centurion(n.data)[1])
|
||||
return True
|
||||
|
||||
if feature == SupportedFeature.SOLAR_DASHBOARD:
|
||||
if n.data[5:9] == b"GOOD":
|
||||
charge, lux, _ = struct.unpack("!BHH", n.data[:5])
|
||||
status = BatteryStatus.DISCHARGING
|
||||
if n.address == 0x10 and lux > 200:
|
||||
status = BatteryStatus.RECHARGING
|
||||
dev.set_battery_info(Battery(charge, None, status, None, lux))
|
||||
return True
|
||||
return False
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def _import_listener_deps():
|
||||
try:
|
||||
from logitech_receiver import base, device, receiver
|
||||
from logitech_receiver.listener import EventsListener
|
||||
except ImportError as e:
|
||||
raise RuntimeError(
|
||||
"logitech_receiver isn't importable -- install it with `pip install solaar`."
|
||||
) from e
|
||||
except ValueError as e:
|
||||
raise RuntimeError(
|
||||
"logitech_receiver failed to import because a GTK3 typelib is missing "
|
||||
f"({e}). Install the same GTK3 + PyGObject packages Solaar's GUI needs "
|
||||
"(e.g. python3-gi + gir1.2-gtk-3.0 on Debian/Ubuntu, or the gtk3/"
|
||||
"python3-gobject equivalents on your distro)."
|
||||
) from e
|
||||
|
||||
class _BatteryEventsListener(EventsListener):
|
||||
def __init__(self, receiver_or_device, on_change):
|
||||
super().__init__(receiver_or_device, self._handle_notification)
|
||||
self._on_change = on_change
|
||||
|
||||
def has_started(self):
|
||||
|
||||
if not self.receiver.isDevice:
|
||||
try:
|
||||
self.receiver.notification_flags = (
|
||||
self.receiver.enable_connection_notifications()
|
||||
)
|
||||
self.receiver.notify_devices()
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"failed enabling notifications for %s", self.receiver
|
||||
)
|
||||
|
||||
def _handle_notification(self, n):
|
||||
if self.receiver.isDevice:
|
||||
try:
|
||||
_process_battery_notification(self.receiver, n)
|
||||
except Exception:
|
||||
logger.exception("processing %s for %s", n, self.receiver)
|
||||
self._on_change(self.receiver)
|
||||
return
|
||||
|
||||
if n.devnumber == 0xFF:
|
||||
try:
|
||||
_process_battery_notification(self.receiver, n)
|
||||
except Exception:
|
||||
logger.exception("processing receiver notification %s", n)
|
||||
self._on_change(self.receiver)
|
||||
return
|
||||
|
||||
if not (0 < n.devnumber <= 16):
|
||||
logger.warning(
|
||||
"unexpected device number %s in %s", n.devnumber, n
|
||||
)
|
||||
return
|
||||
|
||||
try:
|
||||
dev = self.receiver[n.devnumber]
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"resolving device number %s on %s",
|
||||
n.devnumber,
|
||||
self.receiver,
|
||||
)
|
||||
return
|
||||
|
||||
if not dev:
|
||||
logger.warning(
|
||||
"%s: received %s for invalid device %d",
|
||||
self.receiver,
|
||||
n,
|
||||
n.devnumber,
|
||||
)
|
||||
return
|
||||
|
||||
try:
|
||||
_process_battery_notification(dev, n)
|
||||
except Exception:
|
||||
logger.exception("processing %s for %s", n, dev)
|
||||
|
||||
self._on_change(dev)
|
||||
|
||||
return base, device, receiver, _BatteryEventsListener
|
||||
|
||||
|
||||
def _start_hotplug_watcher(on_hotplug: Callable[[], None]):
|
||||
try:
|
||||
import pyudev
|
||||
except ImportError:
|
||||
logger.warning(
|
||||
"pyudev isn't importable -- hotplugged devices will only be "
|
||||
"noticed on the next --rescan-interval tick, not instantly. "
|
||||
"Install it with `pip install pyudev` (it's a core Solaar "
|
||||
"dependency, so it's normally already present)."
|
||||
)
|
||||
return None
|
||||
|
||||
debounce_lock = threading.Lock()
|
||||
debounce_state: dict[str, threading.Timer | None] = {"timer": None}
|
||||
DEBOUNCE_SECONDS = 0.5
|
||||
|
||||
def _fire():
|
||||
with debounce_lock:
|
||||
debounce_state["timer"] = None
|
||||
on_hotplug()
|
||||
|
||||
def _handle_event(_device):
|
||||
if _device.action not in ("add", "remove"):
|
||||
return
|
||||
with debounce_lock:
|
||||
existing = debounce_state["timer"]
|
||||
if existing is not None:
|
||||
existing.cancel()
|
||||
timer = threading.Timer(DEBOUNCE_SECONDS, _fire)
|
||||
timer.daemon = True
|
||||
debounce_state["timer"] = timer
|
||||
timer.start()
|
||||
|
||||
context = pyudev.Context()
|
||||
monitor = pyudev.Monitor.from_netlink(context)
|
||||
monitor.filter_by(subsystem="hidraw")
|
||||
observer = pyudev.MonitorObserver(monitor, callback=_handle_event)
|
||||
observer.start()
|
||||
return observer
|
||||
|
||||
|
||||
class _ListenerRegistry:
|
||||
def __init__(self, on_change):
|
||||
self._on_change = on_change
|
||||
self._entries = {}
|
||||
self._last_change: dict[int, float] = {}
|
||||
self._lock = threading.Lock()
|
||||
self._rescan_lock = threading.Lock()
|
||||
self._min_rescan_interval = 1.0
|
||||
self._last_rescan_time = 0.0
|
||||
|
||||
self._hidpp_io_lock = threading.RLock()
|
||||
|
||||
def _touch_and_notify(self, dev_or_receiver, *args, **kwargs):
|
||||
with self._lock:
|
||||
self._last_change[id(dev_or_receiver)] = time.time()
|
||||
self._on_change(dev_or_receiver, *args, **kwargs)
|
||||
|
||||
def last_change(self, dev) -> float:
|
||||
with self._lock:
|
||||
return self._last_change.get(id(dev), 0.0)
|
||||
|
||||
def rescan(self):
|
||||
now = time.monotonic()
|
||||
if now - self._last_rescan_time < self._min_rescan_interval:
|
||||
return
|
||||
if not self._rescan_lock.acquire(blocking=False):
|
||||
return
|
||||
|
||||
try:
|
||||
self._last_rescan_time = now
|
||||
with self._hidpp_io_lock:
|
||||
base, device, receiver, ListenerClass = _import_listener_deps()
|
||||
|
||||
with self._lock:
|
||||
dead = [
|
||||
p
|
||||
for p, (_obj, listener) in self._entries.items()
|
||||
if not listener._active
|
||||
]
|
||||
for p in dead:
|
||||
dying_obj, _dying_listener = self._entries[p]
|
||||
|
||||
if dying_obj.isDevice:
|
||||
ident = getattr(
|
||||
dying_obj, "unitId", None
|
||||
) or getattr(dying_obj, "serial", None)
|
||||
info = getattr(dying_obj, "battery_info", None)
|
||||
if ident and info is not None:
|
||||
for (
|
||||
other_path,
|
||||
(other_obj, _other_listener),
|
||||
) in self._entries.items():
|
||||
if other_path == p or other_obj.isDevice:
|
||||
continue
|
||||
for child in other_obj:
|
||||
child_ident = getattr(
|
||||
child, "unitId", None
|
||||
) or getattr(child, "serial", None)
|
||||
if child_ident == ident:
|
||||
child.set_battery_info(info)
|
||||
break
|
||||
del self._entries[p]
|
||||
known_paths = set(self._entries.keys())
|
||||
|
||||
with self._lock:
|
||||
id_to_entry = {}
|
||||
for path, (obj, listener) in self._entries.items():
|
||||
if obj.isDevice:
|
||||
ident = obj.unitId or obj.serial
|
||||
if ident:
|
||||
id_to_entry[ident] = (path, obj, listener)
|
||||
|
||||
for dev_info in base.receivers_and_devices():
|
||||
if dev_info.path in known_paths:
|
||||
continue
|
||||
try:
|
||||
if dev_info.isDevice:
|
||||
obj = device.create_device(base, dev_info)
|
||||
else:
|
||||
obj = receiver.create_receiver(base, dev_info)
|
||||
except OSError as e:
|
||||
if e.errno == 13:
|
||||
logger.error(
|
||||
"permission denied opening %s -- check the Solaar udev rule "
|
||||
"(rules.d/42-logitech-unify-permissions.rules) is installed",
|
||||
dev_info.path,
|
||||
)
|
||||
else:
|
||||
logger.exception("failed opening %s", dev_info)
|
||||
continue
|
||||
except Exception:
|
||||
logger.exception("failed opening %s", dev_info)
|
||||
continue
|
||||
|
||||
if obj is None:
|
||||
continue
|
||||
|
||||
listener = ListenerClass(obj, self._touch_and_notify)
|
||||
to_join = None
|
||||
|
||||
if obj.isDevice:
|
||||
ident = None
|
||||
try:
|
||||
if obj.protocol >= 2.0:
|
||||
obj.get_ids()
|
||||
ident = obj.unitId or obj.serial
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if ident:
|
||||
with self._lock:
|
||||
existing = id_to_entry.get(ident)
|
||||
if existing:
|
||||
old_path, old_obj, old_listener = existing
|
||||
|
||||
if old_path != dev_info.path:
|
||||
logger.info(
|
||||
"replacing device %s (old path %s) with new path %s",
|
||||
ident,
|
||||
old_path,
|
||||
dev_info.path,
|
||||
)
|
||||
|
||||
if (
|
||||
getattr(obj, "battery_info", None)
|
||||
is None
|
||||
and getattr(
|
||||
old_obj, "battery_info", None
|
||||
)
|
||||
is not None
|
||||
):
|
||||
obj.set_battery_info(
|
||||
old_obj.battery_info
|
||||
)
|
||||
|
||||
old_listener.stop()
|
||||
|
||||
del self._entries[old_path]
|
||||
|
||||
self._entries[dev_info.path] = (
|
||||
obj,
|
||||
listener,
|
||||
)
|
||||
self._last_change[id(obj)] = time.time()
|
||||
|
||||
to_join = old_listener
|
||||
break
|
||||
else:
|
||||
pass
|
||||
else:
|
||||
if (
|
||||
getattr(obj, "battery_info", None)
|
||||
is None
|
||||
):
|
||||
for (
|
||||
_,
|
||||
(other_obj, _other_listener),
|
||||
) in self._entries.items():
|
||||
if other_obj.isDevice:
|
||||
continue
|
||||
for child in other_obj:
|
||||
child_ident = getattr(
|
||||
child, "unitId", None
|
||||
) or getattr(
|
||||
child, "serial", None
|
||||
)
|
||||
if child_ident == ident:
|
||||
obj.set_battery_info(
|
||||
child.battery_info
|
||||
)
|
||||
break
|
||||
if (
|
||||
getattr(
|
||||
obj,
|
||||
"battery_info",
|
||||
None,
|
||||
)
|
||||
is not None
|
||||
):
|
||||
break
|
||||
|
||||
with self._lock:
|
||||
if dev_info.path not in self._entries:
|
||||
self._entries[dev_info.path] = (obj, listener)
|
||||
self._last_change[id(obj)] = time.time()
|
||||
|
||||
listener.start()
|
||||
|
||||
logger.info(
|
||||
"listening on %s (%s)",
|
||||
dev_info.path,
|
||||
"device" if dev_info.isDevice else "receiver",
|
||||
)
|
||||
|
||||
if to_join is not None:
|
||||
try:
|
||||
to_join.join(timeout=1.0)
|
||||
except Exception:
|
||||
logger.exception("error joining replaced listener")
|
||||
del to_join
|
||||
|
||||
finally:
|
||||
self._rescan_lock.release()
|
||||
|
||||
def known_devices(self):
|
||||
with self._lock:
|
||||
entries = list(self._entries.values())
|
||||
|
||||
result = []
|
||||
seen_idents = set()
|
||||
for obj, _listener in entries:
|
||||
if obj.isDevice:
|
||||
ident = obj.unitId or obj.serial
|
||||
if ident and ident in seen_idents:
|
||||
continue
|
||||
if ident:
|
||||
seen_idents.add(ident)
|
||||
result.append(obj)
|
||||
else:
|
||||
for child in obj:
|
||||
ident = child.unitId or child.serial
|
||||
if ident and ident in seen_idents:
|
||||
continue
|
||||
if ident:
|
||||
seen_idents.add(ident)
|
||||
result.append(child)
|
||||
return result
|
||||
|
||||
def stop(self):
|
||||
with self._lock:
|
||||
entries = list(self._entries.values())
|
||||
for _obj, listener in entries:
|
||||
try:
|
||||
listener.stop()
|
||||
except Exception:
|
||||
logger.exception("error stopping listener")
|
||||
for _obj, listener in entries:
|
||||
listener.join(timeout=2.0)
|
||||
|
||||
|
||||
def _snapshot(registry: _ListenerRegistry) -> list[DeviceBattery]:
|
||||
results: list[DeviceBattery] = []
|
||||
|
||||
with registry._hidpp_io_lock:
|
||||
for dev in registry.known_devices():
|
||||
info = dev.battery_info
|
||||
if info is None:
|
||||
try:
|
||||
if dev.ping():
|
||||
info = dev.battery()
|
||||
except Exception:
|
||||
logger.debug(
|
||||
"initial battery() failed for %s", dev, exc_info=True
|
||||
)
|
||||
info = None
|
||||
entry = _to_device_battery(dev, info)
|
||||
if entry is not None:
|
||||
results.append(entry)
|
||||
return results
|
||||
|
||||
|
||||
def _clean_json(path: Path) -> None:
|
||||
_write_json_atomic(path, [])
|
||||
|
||||
|
||||
def _iter_open_devices():
|
||||
try:
|
||||
from logitech_receiver import base, device, receiver
|
||||
except ImportError as e:
|
||||
raise RuntimeError(
|
||||
"logitech_receiver isn't importable -- install it with `pip install solaar`."
|
||||
) from e
|
||||
except ValueError as e:
|
||||
raise RuntimeError(
|
||||
"logitech_receiver failed to import because a GTK3 typelib is missing "
|
||||
f"({e}). Install the same GTK3 + PyGObject packages Solaar's GUI needs "
|
||||
"(e.g. python3-gi + gir1.2-gtk-3.0 on Debian/Ubuntu, or the gtk3/"
|
||||
"python3-gobject equivalents on your distro)."
|
||||
) from e
|
||||
|
||||
for dev_info in base.receivers_and_devices():
|
||||
try:
|
||||
if dev_info.isDevice:
|
||||
d = device.create_device(base, dev_info) # pyright: ignore[reportArgumentType]
|
||||
if d is not None:
|
||||
yield d
|
||||
else:
|
||||
d = receiver.create_receiver(base, dev_info) # pyright: ignore[reportArgumentType]
|
||||
if d is not None:
|
||||
yield from d
|
||||
except OSError as e:
|
||||
if e.errno == 13:
|
||||
logger.error(
|
||||
"permission denied opening %s -- check the Solaar udev rule "
|
||||
"(rules.d/42-logitech-unify-permissions.rules) is installed "
|
||||
"and you're in the right group",
|
||||
dev_info.path,
|
||||
)
|
||||
else:
|
||||
logger.exception("failed opening %s", dev_info)
|
||||
continue
|
||||
except Exception:
|
||||
logger.exception("failed opening %s", dev_info)
|
||||
continue
|
||||
|
||||
|
||||
def _to_device_battery(dev, battery) -> DeviceBattery | None:
|
||||
if battery is None:
|
||||
return None
|
||||
|
||||
percentage = battery.level / 100 if isinstance(battery.level, int) else None
|
||||
state = battery.status.name.lower() if battery.status is not None else None
|
||||
|
||||
serial = (
|
||||
getattr(dev, "serial", None) or getattr(dev, "unitId", None) or None
|
||||
)
|
||||
|
||||
return DeviceBattery(
|
||||
model=dev.name or dev.codename or "Unknown device",
|
||||
nativePath=_find_upower_native_path(serial),
|
||||
serial=serial,
|
||||
type=str(dev.kind) if dev.kind is not None else None,
|
||||
wired=dev.receiver is None,
|
||||
percentage=percentage,
|
||||
state=state,
|
||||
charging=battery.charging(),
|
||||
isPresent=battery.ok(),
|
||||
)
|
||||
|
||||
|
||||
def _read_battery(dev) -> DeviceBattery | None:
|
||||
try:
|
||||
if not dev.ping():
|
||||
return None
|
||||
except Exception:
|
||||
logger.debug("ping failed for %s", dev, exc_info=True)
|
||||
return None
|
||||
|
||||
try:
|
||||
battery = dev.battery()
|
||||
except Exception:
|
||||
logger.debug("battery() failed for %s", dev, exc_info=True)
|
||||
return None
|
||||
|
||||
return _to_device_battery(dev, battery)
|
||||
|
||||
|
||||
def poll_once() -> list[DeviceBattery]:
|
||||
results: list[DeviceBattery] = []
|
||||
seen_idents = set()
|
||||
for dev in _iter_open_devices():
|
||||
try:
|
||||
info = _read_battery(dev)
|
||||
if info is not None:
|
||||
entry = _to_device_battery(dev, info)
|
||||
if entry:
|
||||
ident = entry.serial or (getattr(dev, "unitId", None))
|
||||
if ident and ident in seen_idents:
|
||||
continue
|
||||
if ident:
|
||||
seen_idents.add(ident)
|
||||
results.append(entry)
|
||||
finally:
|
||||
with contextlib.suppress(Exception):
|
||||
dev.close()
|
||||
return results
|
||||
|
||||
|
||||
def _write_json_atomic(path: Path, results: list[DeviceBattery]) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
payload = {
|
||||
"updated": time.time(),
|
||||
"devices": [asdict(r) for r in results],
|
||||
}
|
||||
fd, tmp_path = tempfile.mkstemp(
|
||||
dir=path.parent, prefix=".battery-", suffix=".tmp"
|
||||
)
|
||||
try:
|
||||
with os.fdopen(fd, "w") as f:
|
||||
json.dump(payload, f, indent=2)
|
||||
os.replace(tmp_path, path)
|
||||
except Exception:
|
||||
Path(tmp_path).unlink(missing_ok=True)
|
||||
raise
|
||||
|
||||
|
||||
@app.command()
|
||||
def daemon(
|
||||
rescan_interval: float = typer.Option(
|
||||
60.0,
|
||||
"--rescan-interval",
|
||||
"-i",
|
||||
help=(
|
||||
"Seconds between fallback rescans. This is NOT a battery poll "
|
||||
"interval -- battery updates are event-driven and written as "
|
||||
"soon as a device reports a change. New/removed devices "
|
||||
"(e.g. plugging a keyboard in to charge) are normally noticed "
|
||||
"within milliseconds via a udev hotplug watcher; this interval "
|
||||
"is only a safety net in case a udev event is ever missed."
|
||||
),
|
||||
),
|
||||
out: Path = typer.Option(
|
||||
DEFAULT_OUTPUT,
|
||||
"--out",
|
||||
"-o",
|
||||
help="Where to write the JSON status file.",
|
||||
),
|
||||
lock_file: Path = typer.Option(
|
||||
DEFAULT_LOCK,
|
||||
"--lock-file",
|
||||
help="Path used to ensure only one daemon runs at a time.",
|
||||
),
|
||||
verbose: bool = typer.Option(
|
||||
False,
|
||||
"--verbose",
|
||||
"-v",
|
||||
help="Log every listener start and battery-change write to stderr.",
|
||||
),
|
||||
):
|
||||
lock_fd = _acquire_singleton_lock(lock_file)
|
||||
if lock_fd is None:
|
||||
try:
|
||||
holder_pid = lock_file.read_text().strip()
|
||||
except OSError:
|
||||
holder_pid = "unknown"
|
||||
typer.echo(
|
||||
f"error: a battery daemon is already running (pid {holder_pid}, lock: {lock_file})",
|
||||
err=True,
|
||||
)
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
if verbose:
|
||||
logging.basicConfig(
|
||||
level=logging.INFO, format="%(asctime)s %(name)s: %(message)s"
|
||||
)
|
||||
|
||||
write_lock = threading.Lock()
|
||||
last_payload = None
|
||||
|
||||
pending_write_timer: list[threading.Timer | None] = [None]
|
||||
pending_write_lock = threading.Lock()
|
||||
WRITE_SETTLE_SECONDS = 0.3
|
||||
|
||||
write_seq_lock = threading.Lock()
|
||||
write_seq = 0
|
||||
last_written_seq = 0
|
||||
|
||||
def write_if_changed():
|
||||
nonlocal last_payload, write_seq, last_written_seq
|
||||
with write_seq_lock:
|
||||
write_seq += 1
|
||||
my_seq = write_seq
|
||||
|
||||
results = _snapshot(registry)
|
||||
with write_lock:
|
||||
with write_seq_lock:
|
||||
if my_seq <= last_written_seq:
|
||||
return
|
||||
last_written_seq = my_seq
|
||||
payload = [asdict(r) for r in results]
|
||||
if payload != last_payload:
|
||||
_write_json_atomic(out, results)
|
||||
last_payload = payload
|
||||
logger.info(
|
||||
"battery status changed, wrote %d device(s)", len(results)
|
||||
)
|
||||
|
||||
def write_if_changed_coalesced():
|
||||
with pending_write_lock:
|
||||
existing = pending_write_timer[0]
|
||||
if existing is not None:
|
||||
existing.cancel()
|
||||
timer = threading.Timer(WRITE_SETTLE_SECONDS, write_if_changed)
|
||||
timer.daemon = True
|
||||
pending_write_timer[0] = timer
|
||||
timer.start()
|
||||
|
||||
def on_change(_device_or_receiver, alert=None, reason=None):
|
||||
write_if_changed_coalesced()
|
||||
|
||||
registry = _ListenerRegistry(on_change)
|
||||
|
||||
def rescan_and_write():
|
||||
try:
|
||||
registry.rescan()
|
||||
except Exception:
|
||||
logger.exception("rescan failed")
|
||||
write_if_changed_coalesced()
|
||||
|
||||
try:
|
||||
registry.rescan()
|
||||
except RuntimeError as e:
|
||||
typer.echo(f"error: {e}", err=True)
|
||||
raise typer.Exit(code=1) from None
|
||||
|
||||
write_if_changed()
|
||||
|
||||
hotplug_observer = _start_hotplug_watcher(rescan_and_write)
|
||||
|
||||
running = True
|
||||
|
||||
def _stop(signum, frame):
|
||||
nonlocal running
|
||||
running = False
|
||||
|
||||
signal.signal(signal.SIGINT, _stop)
|
||||
signal.signal(signal.SIGTERM, _stop)
|
||||
|
||||
typer.echo(
|
||||
f"Listening for battery events, writing to {out} (lock: {lock_file})"
|
||||
)
|
||||
|
||||
try:
|
||||
while running:
|
||||
remaining = rescan_interval
|
||||
while running and remaining > 0:
|
||||
step = min(0.2, remaining)
|
||||
time.sleep(step)
|
||||
remaining -= step
|
||||
if running:
|
||||
rescan_and_write()
|
||||
finally:
|
||||
if hotplug_observer is not None:
|
||||
with contextlib.suppress(Exception):
|
||||
hotplug_observer.stop()
|
||||
with contextlib.suppress(Exception):
|
||||
_clean_json(out)
|
||||
|
||||
registry.stop()
|
||||
typer.echo("Stopped.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
@@ -116,10 +116,15 @@ def list_presets(
|
||||
@app.command()
|
||||
def generate(
|
||||
image_path: Path | None = typer.Option(
|
||||
None, help="Path to source image. Required for image mode."
|
||||
None,
|
||||
"--image-path",
|
||||
"-i",
|
||||
help="Path to source image. Required for image mode.",
|
||||
),
|
||||
scheme: str | None = typer.Option(
|
||||
None,
|
||||
"--scheme",
|
||||
"-s",
|
||||
help="Color scheme algorithm to use for image mode. Ignored in preset mode.",
|
||||
autocompletion=_complete_scheme_name,
|
||||
),
|
||||
@@ -130,16 +135,26 @@ def generate(
|
||||
),
|
||||
mode: str | None = typer.Option(
|
||||
None,
|
||||
"--mode",
|
||||
"-m",
|
||||
help="Mode of the preset scheme (dark or light).",
|
||||
autocompletion=_complete_mode,
|
||||
),
|
||||
accent: str | None = typer.Option(
|
||||
None,
|
||||
"--accent",
|
||||
"-a",
|
||||
help="Accent for schemes that support it (e.g. mauve).",
|
||||
autocompletion=_complete_accent,
|
||||
),
|
||||
preview: bool = typer.Option(
|
||||
False,
|
||||
"--preview",
|
||||
"-p",
|
||||
help="Preview scheme - internal use",
|
||||
),
|
||||
):
|
||||
if not any([image_path, scheme, preset, mode, accent]):
|
||||
if not any([image_path, scheme, preset, mode, accent, preview]):
|
||||
print(
|
||||
"Hint: use --preset <scheme>:<variant> or --image-path <path>",
|
||||
file=sys.stderr,
|
||||
@@ -685,10 +700,6 @@ def generate(
|
||||
|
||||
variant_val = scheme if not preset else p_variant
|
||||
|
||||
if smart and not preset:
|
||||
apply_gtk_mode(effective_mode)
|
||||
apply_qt_mode(effective_mode, HOME)
|
||||
|
||||
output_dict = {
|
||||
"name": name,
|
||||
"flavor": flavor,
|
||||
@@ -698,6 +709,14 @@ def generate(
|
||||
"seed": seed.to_int(),
|
||||
}
|
||||
|
||||
if preview:
|
||||
print(json.dumps(output_dict))
|
||||
return
|
||||
|
||||
if smart and not preset:
|
||||
apply_gtk_mode(effective_mode)
|
||||
apply_qt_mode(effective_mode, HOME)
|
||||
|
||||
if TEMPLATE_DIR is not None:
|
||||
wp = str(WALL_PATH)
|
||||
ctx = build_template_context(
|
||||
|
||||
+3
-4
@@ -10,12 +10,11 @@ dependencies = [
|
||||
"typer",
|
||||
"pillow",
|
||||
"jinja2",
|
||||
"materialyoucolor"
|
||||
"materialyoucolor",
|
||||
"solaar",
|
||||
"pytest"
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = ["pytest"]
|
||||
|
||||
[project.scripts]
|
||||
zshell-cli = "zshell:main"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user