1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-07 22:15:38 -05:00

niri: add screenshot IPCs with swappy

This commit is contained in:
bbedward
2025-11-04 13:39:51 -05:00
parent 81c3110d0d
commit fa08b39bb0

View File

@@ -37,6 +37,9 @@ Singleton {
property bool matugenSuppression: false
property bool configGenerationPending: false
readonly property string screenshotsDir: Paths.strip(StandardPaths.writableLocation(StandardPaths.PicturesLocation)) + "/Screenshots"
property string pendingScreenshotPath: ""
signal windowUrgentChanged
function setWorkspaces(newMap) {
@@ -271,6 +274,9 @@ Singleton {
case 'WorkspaceUrgencyChanged':
handleWorkspaceUrgencyChanged(event.WorkspaceUrgencyChanged)
break
case 'ScreenshotCaptured':
handleScreenshotCaptured(event.ScreenshotCaptured)
break
}
}
@@ -539,6 +545,18 @@ Singleton {
windowUrgentChanged()
}
function handleScreenshotCaptured(data) {
if (!data.path)
return
if (pendingScreenshotPath && data.path === pendingScreenshotPath) {
Quickshell.execDetached({
command: ["swappy", "-f", data.path]
})
pendingScreenshotPath = ""
}
}
function updateCurrentOutputWorkspaces() {
if (!currentOutput) {
currentOutputWorkspaces = allWorkspaces
@@ -632,6 +650,56 @@ Singleton {
})
}
function screenshot() {
pendingScreenshotPath = ""
const timestamp = Date.now()
const path = `${screenshotsDir}/dms-screenshot-${timestamp}.png`
pendingScreenshotPath = path
return send({
"Action": {
"Screenshot": {
"show_pointer": true,
"path": path
}
}
})
}
function screenshotScreen() {
pendingScreenshotPath = ""
const timestamp = Date.now()
const path = `${screenshotsDir}/dms-screenshot-${timestamp}.png`
pendingScreenshotPath = path
return send({
"Action": {
"ScreenshotScreen": {
"write_to_disk": true,
"show_pointer": true,
"path": path
}
}
})
}
function screenshotWindow() {
pendingScreenshotPath = ""
const timestamp = Date.now()
const path = `${screenshotsDir}/dms-screenshot-${timestamp}.png`
pendingScreenshotPath = path
return send({
"Action": {
"ScreenshotWindow": {
"write_to_disk": true,
"show_pointer": true,
"path": path
}
}
})
}
function getCurrentOutputWorkspaceNumbers() {
return currentOutputWorkspaces.map(w => w.idx + 1)
}
@@ -904,4 +972,38 @@ window-rule {
writeBindsProcess.command = ["sh", "-c", `mkdir -p "${niriDmsDir}" && cp --no-preserve=mode "${sourceBlurrulePath}" "${blurrulePath}"`]
writeBindsProcess.running = true
}
IpcHandler {
function screenshot(): string {
if (!CompositorService.isNiri) {
return "NIRI_NOT_AVAILABLE"
}
if (NiriService.screenshot()) {
return "SCREENSHOT_SUCCESS"
}
return "SCREENSHOT_FAILED"
}
function screenshotScreen(): string {
if (!CompositorService.isNiri) {
return "NIRI_NOT_AVAILABLE"
}
if (NiriService.screenshotScreen()) {
return "SCREENSHOT_SCREEN_SUCCESS"
}
return "SCREENSHOT_SCREEN_FAILED"
}
function screenshotWindow(): string {
if (!CompositorService.isNiri) {
return "NIRI_NOT_AVAILABLE"
}
if (NiriService.screenshotWindow()) {
return "SCREENSHOT_WINDOW_SUCCESS"
}
return "SCREENSHOT_WINDOW_FAILED"
}
target: "niri"
}
}