mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-10 07:25:37 -05:00
niri: add screenshot IPCs with swappy
This commit is contained in:
@@ -37,6 +37,9 @@ Singleton {
|
|||||||
property bool matugenSuppression: false
|
property bool matugenSuppression: false
|
||||||
property bool configGenerationPending: false
|
property bool configGenerationPending: false
|
||||||
|
|
||||||
|
readonly property string screenshotsDir: Paths.strip(StandardPaths.writableLocation(StandardPaths.PicturesLocation)) + "/Screenshots"
|
||||||
|
property string pendingScreenshotPath: ""
|
||||||
|
|
||||||
signal windowUrgentChanged
|
signal windowUrgentChanged
|
||||||
|
|
||||||
function setWorkspaces(newMap) {
|
function setWorkspaces(newMap) {
|
||||||
@@ -271,6 +274,9 @@ Singleton {
|
|||||||
case 'WorkspaceUrgencyChanged':
|
case 'WorkspaceUrgencyChanged':
|
||||||
handleWorkspaceUrgencyChanged(event.WorkspaceUrgencyChanged)
|
handleWorkspaceUrgencyChanged(event.WorkspaceUrgencyChanged)
|
||||||
break
|
break
|
||||||
|
case 'ScreenshotCaptured':
|
||||||
|
handleScreenshotCaptured(event.ScreenshotCaptured)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,6 +545,18 @@ Singleton {
|
|||||||
windowUrgentChanged()
|
windowUrgentChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleScreenshotCaptured(data) {
|
||||||
|
if (!data.path)
|
||||||
|
return
|
||||||
|
|
||||||
|
if (pendingScreenshotPath && data.path === pendingScreenshotPath) {
|
||||||
|
Quickshell.execDetached({
|
||||||
|
command: ["swappy", "-f", data.path]
|
||||||
|
})
|
||||||
|
pendingScreenshotPath = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function updateCurrentOutputWorkspaces() {
|
function updateCurrentOutputWorkspaces() {
|
||||||
if (!currentOutput) {
|
if (!currentOutput) {
|
||||||
currentOutputWorkspaces = allWorkspaces
|
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() {
|
function getCurrentOutputWorkspaceNumbers() {
|
||||||
return currentOutputWorkspaces.map(w => w.idx + 1)
|
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.command = ["sh", "-c", `mkdir -p "${niriDmsDir}" && cp --no-preserve=mode "${sourceBlurrulePath}" "${blurrulePath}"`]
|
||||||
writeBindsProcess.running = true
|
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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user