1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-04-03 20:32:07 -04:00

Add support for linux-wallpaperengine wallpapers (#191)

* Add support for linux-wallpaperengine wallpapers

* Remove unnecessary onCompleted hook
This commit is contained in:
Aziz Hasanain
2025-09-12 19:13:14 +03:00
committed by GitHub
parent c3759dc542
commit c8cb5dc146
6 changed files with 262 additions and 28 deletions

View File

@@ -1,3 +1,4 @@
import QtCore
import QtQuick
import QtQuick.Controls
import QtQuick.Effects
@@ -75,6 +76,12 @@ Item {
anchors.fill: parent
source: {
var currentWallpaper = SessionData.getMonitorWallpaper(screenName)
if (screenName && currentWallpaper && currentWallpaper.startsWith("we:")) {
const cacheHome = StandardPaths.writableLocation(StandardPaths.CacheLocation).toString()
const baseDir = cacheHome.startsWith("file://") ? cacheHome.substring(7) : cacheHome
const screenshotPath = baseDir + "/dankshell/we_screenshots" + "/" + currentWallpaper.substring(3) + ".jpg"
return screenshotPath
}
return (currentWallpaper && !currentWallpaper.startsWith("#")) ? currentWallpaper : ""
}
fillMode: Image.PreserveAspectCrop

View File

@@ -1,3 +1,4 @@
import QtCore
import QtQuick
import QtQuick.Controls
import QtQuick.Effects
@@ -141,10 +142,28 @@ Item {
CachingImage {
anchors.fill: parent
anchors.margins: 1
property var weExtensions: [".jpg", ".png", ".webp", ".gif", ".jpeg"]
property int weExtIndex: 0
source: {
var currentWallpaper = SessionData.perMonitorWallpaper ? SessionData.getMonitorWallpaper(selectedMonitorName) : SessionData.wallpaperPath
if (currentWallpaper && currentWallpaper.startsWith("we:")) {
var sceneId = currentWallpaper.substring(3)
return StandardPaths.writableLocation(StandardPaths.HomeLocation)
+ "/.local/share/Steam/steamapps/workshop/content/431960/"
+ sceneId + "/preview" + weExtensions[weExtIndex]
}
return (currentWallpaper !== "" && !currentWallpaper.startsWith("#")) ? "file://" + currentWallpaper : ""
}
onStatusChanged: {
var currentWallpaper = SessionData.perMonitorWallpaper ? SessionData.getMonitorWallpaper(selectedMonitorName) : SessionData.wallpaperPath
if (currentWallpaper.startsWith("we:") && status === Image.Error && weExtIndex < weExtensions.length - 1) {
weExtIndex++
source = StandardPaths.writableLocation(StandardPaths.HomeLocation)
+ "/.local/share/Steam/steamapps/workshop/content/431960/"
+ currentWallpaper.substring(3)
+ "/preview" + weExtensions[weExtIndex]
}
}
fillMode: Image.PreserveAspectCrop
visible: {
var currentWallpaper = SessionData.perMonitorWallpaper ? SessionData.getMonitorWallpaper(selectedMonitorName) : SessionData.wallpaperPath
@@ -234,6 +253,30 @@ Item {
}
}
Rectangle {
width: 32; height: 32; radius: 16
color: Qt.rgba(255, 255, 255, 0.9)
DankIcon {
anchors.centerIn: parent
name: "movie" // 🎬 icon for WE
size: 18
color: "black"
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
if (parentModal) {
parentModal.allowFocusOverride = true
parentModal.shouldHaveFocus = false
}
weBrowser.open()
}
}
}
Rectangle {
width: 32
height: 32
@@ -347,11 +390,11 @@ Item {
iconSize: Theme.iconSizeSmall
enabled: {
var currentWallpaper = SessionData.perMonitorWallpaper ? SessionData.getMonitorWallpaper(selectedMonitorName) : SessionData.wallpaperPath
return currentWallpaper && !currentWallpaper.startsWith("#")
return currentWallpaper && !currentWallpaper.startsWith("#") && !currentWallpaper.startsWith("we")
}
opacity: {
var currentWallpaper = SessionData.perMonitorWallpaper ? SessionData.getMonitorWallpaper(selectedMonitorName) : SessionData.wallpaperPath
return (currentWallpaper && !currentWallpaper.startsWith("#")) ? 1 : 0.5
return (currentWallpaper && !currentWallpaper.startsWith("#") && !currentWallpaper.startsWith("we")) ? 1 : 0.5
}
backgroundColor: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.5)
iconColor: Theme.surfaceText
@@ -370,11 +413,11 @@ Item {
iconSize: Theme.iconSizeSmall
enabled: {
var currentWallpaper = SessionData.perMonitorWallpaper ? SessionData.getMonitorWallpaper(selectedMonitorName) : SessionData.wallpaperPath
return currentWallpaper && !currentWallpaper.startsWith("#")
return currentWallpaper && !currentWallpaper.startsWith("#") && !currentWallpaper.startsWith("we")
}
opacity: {
var currentWallpaper = SessionData.perMonitorWallpaper ? SessionData.getMonitorWallpaper(selectedMonitorName) : SessionData.wallpaperPath
return (currentWallpaper && !currentWallpaper.startsWith("#")) ? 1 : 0.5
return (currentWallpaper && !currentWallpaper.startsWith("#") && !currentWallpaper.startsWith("we")) ? 1 : 0.5
}
backgroundColor: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.5)
iconColor: Theme.surfaceText
@@ -1424,6 +1467,38 @@ Item {
}
}
FileBrowserModal {
id: weBrowser
browserTitle: "Select Wallpaper Engine Scene"
browserIcon: "movie"
browserType: "we"
fileExtensions: [] // only show dirs
// override homeDir to point to Steam workshop path
homeDir: StandardPaths.writableLocation(StandardPaths.HomeLocation)
+ "/.local/share/Steam/steamapps/workshop/content/431960"
// ensure we start there
Component.onCompleted: currentPath = homeDir
function getLastPath() {
return homeDir
}
onFileSelected: folderPath => {
var sceneId = folderPath.split("/").pop()
var weSource = "we:" + sceneId
if (SessionData.perMonitorWallpaper) {
SessionData.setMonitorWallpaper(selectedMonitorName, weSource)
} else {
SessionData.setWallpaper(weSource)
}
close()
}
}
DankColorPicker {
id: colorPicker

View File

@@ -2,8 +2,10 @@ import QtQuick
import Quickshell
import Quickshell.Wayland
import Quickshell.Widgets
import Quickshell.Io
import qs.Common
import qs.Widgets
import qs.Modules
LazyLoader {
active: true
@@ -36,20 +38,38 @@ LazyLoader {
property bool isColorSource: source.startsWith("#")
property Image current: one
WallpaperEngineProc {
id: weProc
monitor: modelData.name
}
Component.onDestruction: {
weProc.stop()
}
onSourceChanged: {
if (!source) {
current = null
one.source = ""
two.source = ""
} else if (isColorSource) {
const isWE = source.startsWith("we:")
if (isWE) {
current = null
one.source = ""
two.source = ""
weProc.start(source.substring(3)) // strip "we:"
} else {
if (current === one)
two.update()
else
one.update()
weProc.stop()
if (!source) {
current = null
one.source = ""
two.source = ""
} else if (isColorSource) {
current = null
one.source = ""
two.source = ""
} else {
if (current === one)
two.update()
else
one.update()
}
}
}

View File

@@ -0,0 +1,62 @@
import QtCore
import QtQuick
import Quickshell.Io
import Quickshell
Item {
id: root
property string monitor: ""
property string sceneId: ""
property string pendingSceneId: ""
Process {
id: weProcess
running: false
command: []
}
Process {
id: killer
running: false
command: []
onExited: (code) => {
if (pendingSceneId !== "") {
const cacheHome = StandardPaths.writableLocation(StandardPaths.CacheLocation).toString()
const baseDir = cacheHome.startsWith("file://") ? cacheHome.substring(7) : cacheHome
const outDir = baseDir + "/dankshell/we_screenshots"
const outPath = outDir + "/" + pendingSceneId + ".jpg"
Quickshell.execDetached(["mkdir", "-p", outDir])
// only spawn after killer has done its job
weProcess.command = [
"linux-wallpaperengine",
"--screen-root", monitor,
"--screenshot",
outPath,
pendingSceneId,
"--silent"
]
weProcess.running = true
pendingSceneId = ""
}
}
}
function start(newSceneId) {
sceneId = newSceneId
pendingSceneId = newSceneId
stop()
}
function stop() {
if (weProcess.running) {
weProcess.running = false
}
killer.command = [
"pkill", "-f",
"linux-wallpaperengine --screen-root " + monitor
]
killer.running = true
}
}