Skip to content

Commit 3fb7f0e

Browse files
authored
Merge pull request #599 from Duncan-Rose/main
Niri Animation Picker - added control center widget, fixed relative pathing for nested configs
2 parents 62fcc94 + 1e7e920 commit 3fb7f0e

3 files changed

Lines changed: 54 additions & 6 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import QtQuick
2+
import Quickshell
3+
import qs.Widgets
4+
5+
NIconButtonHot {
6+
property ShellScreen screen
7+
property var pluginApi: null
8+
9+
icon: "sparkles"
10+
tooltipText: pluginApi?.tr("widget.tooltip")
11+
onClicked: {
12+
if (pluginApi) {
13+
pluginApi.togglePanel(screen)
14+
}
15+
}
16+
}

niri-animation-picker/Panel.qml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ Item {
4444
? resolvedAnimDir.replace(/\/+$/, "").split("/").pop()
4545
: "animations"
4646

47+
// Relative path from the target file's directory to the animations folder
48+
// e.g. target=~/.config/niri/modules/animations.kdl, animDir=~/.config/niri/animations
49+
// → relativePath = "../animations"
50+
readonly property string relativePath: {
51+
if (resolvedAnimDir === "" || resolvedTargetFile === "") return folderName
52+
var targetDir = resolvedTargetFile.split("/").slice(0, -1).join("/")
53+
// Will be computed properly via python in applyFile, this is just for display
54+
return resolvedAnimDir
55+
}
56+
4757
// ── Processes ─────────────────────────────────────────────────────────────
4858

4959
Process {
@@ -57,8 +67,9 @@ Item {
5767
`ls "${root.resolvedAnimDir}"/*.kdl 2>/dev/null | xargs -n1 basename 2>/dev/null | grep -v "^${targetBasename}$"`]
5868
listFiles.running = true
5969

70+
// Read current include match any path ending with folder name and kdl
6071
readCurrentInclude.command = ["bash", "-c",
61-
`grep -oP '${root.folderName}/[^"/]+\\.kdl' "${root.resolvedTargetFile}" 2>/dev/null | head -1 | xargs -I{} basename {} 2>/dev/null || true`]
72+
`grep -oP 'include "\\K[^"]+/${root.folderName}/[^"]+\\.kdl(?=")' "${root.resolvedTargetFile}" 2>/dev/null | head -1 | xargs -I{} basename {} 2>/dev/null || true`]
6273
readCurrentInclude.running = true
6374
}
6475
}
@@ -112,12 +123,32 @@ Item {
112123
root.writing = true
113124
root.statusMessage = ""
114125

115-
var folder = root.folderName
126+
var animDir = root.resolvedAnimDir
116127
var target = root.resolvedTargetFile
128+
var folder = root.folderName
117129

118130
writeInclude.command = [
119-
"bash", "-c",
120-
`sed -i '/^include "\\.\\/` + folder + `\\/.*\\.kdl"$/d' '` + target + `' && sed -i -e '$a\\' '` + target + `' && printf 'include "./${folder}/${filename}"\\n' >> '` + target + `'`
131+
"python3", "-c",
132+
"import sys, os, re\n" +
133+
"anim_dir = sys.argv[1]\n" +
134+
"target = sys.argv[2]\n" +
135+
"filename = sys.argv[3]\n" +
136+
"folder = sys.argv[4]\n" +
137+
"target_dir = os.path.dirname(os.path.abspath(target))\n" +
138+
"rel = os.path.relpath(anim_dir, target_dir)\n" +
139+
"include_line = f'include \"./{rel}/{filename}\"'\n" +
140+
"try:\n" +
141+
" f = open(target); lines = f.readlines(); f.close()\n" +
142+
"except FileNotFoundError:\n" +
143+
" lines = []\n" +
144+
// Remove lines that match any relative path ending in folder name + kdl
145+
"pat = re.compile(r'^include \"[^\"]*/' + folder + r'/[^\"]+\\.kdl\"\\s*$')\n" +
146+
"lines = [l for l in lines if not pat.match(l.strip())]\n" +
147+
"if lines and not lines[-1].endswith('\\n'):\n" +
148+
" lines[-1] += '\\n'\n" +
149+
"lines.append(include_line + '\\n')\n" +
150+
"f = open(target, 'w'); f.writelines(lines); f.close()",
151+
animDir, target, filename, folder
121152
]
122153
writeInclude.running = true
123154
}

niri-animation-picker/manifest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"id": "niri-animation-picker",
33
"name": "Niri Animation Picker",
4-
"version": "1.1.2",
4+
"version": "1.1.3",
55
"minNoctaliaVersion": "3.6.0",
66
"author": "Duncan-Rose",
77
"license": "MIT",
8-
"repository": "",
8+
"repository": "https://github.com/noctalia-dev/noctalia-plugins",
99
"description": "Pick a KDL animation preset and write it as an include into your niri config",
1010
"tags": [
1111
"Fun",
@@ -16,6 +16,7 @@
1616
"entryPoints": {
1717
"barWidget": "BarWidget.qml",
1818
"panel": "Panel.qml",
19+
"controlCenterWidget": "ControlCenterWidget.qml",
1920
"settings": "Settings.qml"
2021
},
2122
"dependencies": {

0 commit comments

Comments
 (0)