aboutsummaryrefslogtreecommitdiffstats
path: root/config/quickshell/modules/common/widgets/CliphistImage.qml
diff options
context:
space:
mode:
authorKiran George <kirangeorge1995@gmail.com>2025-06-09 11:30:08 +0530
committerKiran George <kirangeorge1995@gmail.com>2025-06-09 11:30:08 +0530
commit952aa63147c9fb28f6ace6f0bc7ccf45ced1299a (patch)
tree306e6d86603a162c00bc5113b56baac0fe7bec7c /config/quickshell/modules/common/widgets/CliphistImage.qml
parent4cf0d0bd5930da76e60f6770de3ee97c10ca7024 (diff)
Overview v2
Diffstat (limited to 'config/quickshell/modules/common/widgets/CliphistImage.qml')
-rw-r--r--config/quickshell/modules/common/widgets/CliphistImage.qml101
1 files changed, 101 insertions, 0 deletions
diff --git a/config/quickshell/modules/common/widgets/CliphistImage.qml b/config/quickshell/modules/common/widgets/CliphistImage.qml
new file mode 100644
index 00000000..9de34450
--- /dev/null
+++ b/config/quickshell/modules/common/widgets/CliphistImage.qml
@@ -0,0 +1,101 @@
+import "root:/modules/common"
+import "root:/modules/common/widgets"
+import "root:/services"
+import "root:/modules/common/functions/string_utils.js" as StringUtils
+import "root:/modules/common/functions/file_utils.js" as FileUtils
+import Qt5Compat.GraphicalEffects
+import Qt.labs.platform
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Layouts
+import Quickshell.Io
+import Quickshell.Widgets
+import Quickshell.Hyprland
+
+Rectangle {
+ id: root
+ property string entry
+ property real maxWidth
+ property real maxHeight
+
+ property string imageDecodePath: Directories.cliphistDecode
+ property string imageDecodeFileName: `${entryNumber}`
+ property string imageDecodeFilePath: `${imageDecodePath}/${imageDecodeFileName}`
+ property string source
+
+ property int entryNumber: {
+ if (!root.entry) return 0
+ const match = root.entry.match(/^(\d+)\t/)
+ return match ? parseInt(match[1]) : 0
+ }
+ property int imageWidth: {
+ if (!root.entry) return 0
+ const match = root.entry.match(/(\d+)x(\d+)/)
+ return match ? parseInt(match[1]) : 0
+ }
+ property int imageHeight: {
+ if (!root.entry) return 0
+ const match = root.entry.match(/(\d+)x(\d+)/)
+ return match ? parseInt(match[2]) : 0
+ }
+ property real scale: {
+ return Math.min(
+ root.maxWidth / imageWidth,
+ root.maxHeight / imageHeight,
+ 1
+ )
+ }
+
+ color: Appearance.colors.colLayer1
+ radius: Appearance.rounding.small
+ implicitHeight: imageHeight * scale
+ implicitWidth: imageWidth * scale
+
+ Component.onCompleted: {
+ decodeImageProcess.running = true
+ }
+
+ Process {
+ id: decodeImageProcess
+ command: ["bash", "-c",
+ `[ -f ${imageDecodeFilePath} ] || echo '${StringUtils.shellSingleQuoteEscape(root.entry)}' | cliphist decode > '${imageDecodeFilePath}'`
+ ]
+ onExited: (exitCode, exitStatus) => {
+ if (exitCode === 0) {
+ root.source = imageDecodeFilePath
+ } else {
+ console.error("[CliphistImage] Failed to decode image for entry:", root.entry)
+ root.source = ""
+ }
+ }
+ }
+
+ Component.onDestruction: {
+ Hyprland.dispatch(`exec bash -c "[ -f '${imageDecodeFilePath}' ] && rm -f '${imageDecodeFilePath}'"`)
+ }
+
+ Image {
+ id: image
+ anchors.fill: parent
+
+ source: Qt.resolvedUrl(root.source)
+ fillMode: Image.PreserveAspectFit
+ antialiasing: true
+ asynchronous: true
+
+ width: root.imageWidth * root.scale
+ height: root.imageHeight * root.scale
+ sourceSize.width: width
+ sourceSize.height: height
+
+ layer.enabled: true
+ layer.effect: OpacityMask {
+ maskSource: Rectangle {
+ width: image.width
+ height: image.height
+ radius: root.radius
+ }
+ }
+ }
+}
+
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage