Skip to content

Commit 53fb927

Browse files
committed
niri: color and layout config generation
1 parent fb5aa03 commit 53fb927

File tree

5 files changed

+178
-9
lines changed

5 files changed

+178
-9
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ sudo sh -c "curl -L https://github.com/AvengeMedia/dgop/releases/latest/download
315315

316316
A lot of options are subject to personal preference, but the below sets a good starting point for most features.
317317

318-
### Niri Integration
318+
### niri Integration
319319

320320
Add to your niri config
321321

@@ -395,6 +395,17 @@ binds {
395395
}
396396
```
397397

398+
#### niri theming
399+
400+
If using a niri build newer than [3933903](https://github.com/YaLTeR/niri/commit/39339032cee3453faa54c361a38db6d83756f750), you can synchronize colors and gaps with the shell settings by adding the following to your niri config.
401+
402+
```bash
403+
# For colors
404+
echo -e 'include "dms/colors.kdl"' >> ~/.config/niri/config.kdl
405+
# For gaps, border widths, certain window rules
406+
echo -e 'include "dms/layout.kdl"' >> ~/.config/niri/config.kdl
407+
```
408+
398409
### Hyprland Integration
399410

400411
Add to your Hyprland config (`~/.config/hypr/hyprland.conf`):

Services/CompositorService.qml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Singleton {
8282

8383
Component.onCompleted: {
8484
detectCompositor()
85+
NiriService.generateNiriLayoutConfig()
8586
}
8687

8788
function filterCurrentWorkspace(toplevels, screen) {
@@ -192,6 +193,7 @@ Singleton {
192193
root.isHyprland = false
193194
root.compositor = "niri"
194195
console.log("CompositorService: Detected Niri with socket:", root.niriSocket)
196+
NiriService.generateNiriBinds()
195197
} else {
196198
root.isHyprland = false
197199
root.isNiri = true
@@ -200,4 +202,4 @@ Singleton {
200202
}
201203
}
202204
}
203-
}
205+
}

Services/NiriService.qml

Lines changed: 107 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ pragma Singleton
22

33
pragma ComponentBehavior: Bound
44

5+
import QtCore
56
import QtQuick
67
import Quickshell
78
import Quickshell.Io
89
import Quickshell.Wayland
10+
import qs.Common
911

1012
Singleton {
1113
id: root
@@ -31,6 +33,7 @@ Singleton {
3133
property bool suppressConfigToast: true
3234
property bool suppressNextConfigToast: false
3335
property bool matugenSuppression: false
36+
property bool configGenerationPending: false
3437

3538
readonly property string socketPath: Quickshell.env("NIRI_SOCKET")
3639

@@ -412,13 +415,13 @@ Singleton {
412415
}
413416

414417
function doScreenTransition() {
415-
send({
416-
"Action": {
417-
"DoScreenTransition": {
418-
"delay_ms": 0,
418+
return send({
419+
"Action": {
420+
"DoScreenTransition": {
421+
"delay_ms": 0,
422+
}
419423
}
420-
}
421-
})
424+
})
422425
}
423426

424427
function switchToWorkspace(workspaceIndex) {
@@ -652,6 +655,7 @@ Singleton {
652655
return result
653656
}
654657

658+
655659
Timer {
656660
id: suppressToastTimer
657661
interval: 3000
@@ -663,4 +667,101 @@ Singleton {
663667
interval: 2000
664668
onTriggered: root.matugenSuppression = false
665669
}
670+
671+
Timer {
672+
id: configGenerationDebounce
673+
interval: 100
674+
onTriggered: root.doGenerateNiriLayoutConfig()
675+
}
676+
677+
function generateNiriLayoutConfig() {
678+
const niriSocket = Quickshell.env("NIRI_SOCKET")
679+
if (!niriSocket || niriSocket.length === 0) {
680+
return
681+
}
682+
683+
if (configGenerationPending) {
684+
return
685+
}
686+
687+
configGenerationPending = true
688+
configGenerationDebounce.restart()
689+
}
690+
691+
function doGenerateNiriLayoutConfig() {
692+
console.log("NiriService: Generating layout config...")
693+
694+
const cornerRadius = typeof SettingsData !== "undefined" ? SettingsData.cornerRadius : 12
695+
const gaps = typeof SettingsData !== "undefined" ? Math.max(4, SettingsData.dankBarSpacing) : 4
696+
697+
const configContent = `layout {
698+
gaps ${gaps}
699+
700+
border {
701+
width 2
702+
}
703+
704+
focus-ring {
705+
width 2
706+
}
666707
}
708+
709+
window-rule {
710+
geometry-corner-radius ${cornerRadius}
711+
clip-to-geometry true
712+
tiled-state true
713+
draw-border-with-background false
714+
}`
715+
716+
const configDir = Paths.strip(StandardPaths.writableLocation(StandardPaths.ConfigLocation))
717+
const niriDmsDir = configDir + "/niri/dms"
718+
const configPath = niriDmsDir + "/layout.kdl"
719+
720+
writeConfigProcess.configContent = configContent
721+
writeConfigProcess.configPath = configPath
722+
writeConfigProcess.command = ["sh", "-c", `mkdir -p "${niriDmsDir}" && cat > "${configPath}" << 'EOF'\n${configContent}\nEOF`]
723+
writeConfigProcess.running = true
724+
configGenerationPending = false
725+
}
726+
727+
function generateNiriBinds() {
728+
console.log("NiriService: Generating binds config...")
729+
730+
const configDir = Paths.strip(StandardPaths.writableLocation(StandardPaths.ConfigLocation))
731+
const niriDmsDir = configDir + "/niri/dms"
732+
const bindsPath = niriDmsDir + "/binds.kdl"
733+
const sourceBindsPath = Paths.strip(Qt.resolvedUrl("niri-binds.kdl"))
734+
735+
writeBindsProcess.bindsPath = bindsPath
736+
writeBindsProcess.command = ["sh", "-c", `mkdir -p "${niriDmsDir}" && cp "${sourceBindsPath}" "${bindsPath}"`]
737+
writeBindsProcess.running = true
738+
}
739+
740+
Process {
741+
id: writeConfigProcess
742+
property string configContent: ""
743+
property string configPath: ""
744+
745+
onExited: exitCode => {
746+
if (exitCode === 0) {
747+
console.log("NiriService: Generated layout config at", configPath)
748+
} else {
749+
console.warn("NiriService: Failed to write layout config, exit code:", exitCode)
750+
}
751+
}
752+
}
753+
754+
Process {
755+
id: writeBindsProcess
756+
property string bindsPath: ""
757+
758+
onExited: exitCode => {
759+
if (exitCode === 0) {
760+
console.log("NiriService: Generated binds config at", bindsPath)
761+
} else {
762+
console.warn("NiriService: Failed to write binds config, exit code:", exitCode)
763+
}
764+
}
765+
}
766+
767+
}

Services/niri-binds.kdl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
binds {
2+
Mod+Space hotkey-overlay-title="Application Launcher" {
3+
spawn "dms" "ipc" "call" "spotlight" "toggle";
4+
}
5+
6+
Mod+V hotkey-overlay-title="Clipboard Manager" {
7+
spawn "dms" "ipc" "call" "clipboard" "toggle";
8+
}
9+
10+
Mod+M hotkey-overlay-title="Task Manager" {
11+
spawn "dms" "ipc" "call" "processlist" "toggle";
12+
}
13+
14+
Mod+Comma hotkey-overlay-title="Settings" {
15+
spawn "dms" "ipc" "call" "settings" "toggle";
16+
}
17+
18+
Mod+N hotkey-overlay-title="Notification Center" {
19+
spawn "dms" "ipc" "call" "notifications" "toggle";
20+
}
21+
22+
Mod+Shift+N hotkey-overlay-title="Notepad" {
23+
spawn "dms" "ipc" "call" "notepad" "toggle";
24+
}
25+
26+
Mod+Alt+L hotkey-overlay-title="Lock Screen" {
27+
spawn "dms" "ipc" "call" "lock" "lock";
28+
}
29+
30+
Ctrl+Alt+Delete hotkey-overlay-title="Task Manager" {
31+
spawn "dms" "ipc" "call" "processlist" "toggle";
32+
}
33+
34+
// Audio
35+
XF86AudioRaiseVolume allow-when-locked=true {
36+
spawn "dms" "ipc" "call" "audio" "increment" "3";
37+
}
38+
XF86AudioLowerVolume allow-when-locked=true {
39+
spawn "dms" "ipc" "call" "audio" "decrement" "3";
40+
}
41+
XF86AudioMute allow-when-locked=true {
42+
spawn "dms" "ipc" "call" "audio" "mute";
43+
}
44+
XF86AudioMicMute allow-when-locked=true {
45+
spawn "dms" "ipc" "call" "audio" "micmute";
46+
}
47+
48+
// BL
49+
XF86MonBrightnessUp allow-when-locked=true {
50+
spawn "dms" "ipc" "call" "brightness" "increment" "5" "";
51+
}
52+
XF86MonBrightnessDown allow-when-locked=true {
53+
spawn "dms" "ipc" "call" "brightness" "decrement" "5" "";
54+
}
55+
}

matugen/configs/niri.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[templates.niri]
22
input_path = './matugen/templates/niri-colors.kdl'
3-
output_path = '~/.config/niri/dankshell-colors.kdl'
3+
output_path = '~/.config/niri/dms/colors.kdl'

0 commit comments

Comments
 (0)