picker: use saveItem

Removes grim dependency
This commit is contained in:
2 * r + 2 * t 2025-08-27 16:24:12 +10:00
parent fc3b08f6cb
commit 6200f400f3
3 changed files with 27 additions and 5 deletions

View file

@ -52,7 +52,6 @@ Dependencies:
- `gcc-libs` - `gcc-libs`
- [`material-symbols`](https://fonts.google.com/icons) - [`material-symbols`](https://fonts.google.com/icons)
- [`caskaydia-cove-nerd`](https://www.nerdfonts.com/font-downloads) - [`caskaydia-cove-nerd`](https://www.nerdfonts.com/font-downloads)
- [`grim`](https://gitlab.freedesktop.org/emersion/grim)
- [`swappy`](https://github.com/jtheoof/swappy) - [`swappy`](https://github.com/jtheoof/swappy)
- [`libqalculate`](https://github.com/Qalculate/libqalculate) - [`libqalculate`](https://github.com/Qalculate/libqalculate)
- [`bash`](https://www.gnu.org/software/bash) - [`bash`](https://www.gnu.org/software/bash)

View file

@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound
import qs.components import qs.components
import qs.services import qs.services
import qs.config import qs.config
import Caelestia
import Quickshell import Quickshell
import Quickshell.Io import Quickshell.Io
import Quickshell.Wayland import Quickshell.Wayland
@ -65,6 +66,12 @@ MouseArea {
} }
} }
function save(): void {
const tmpfile = `file:///tmp/caelestia-picker-${Quickshell.processId}-${Date.now()}.png`;
CUtils.saveItem(screencopy, tmpfile, Qt.rect(Math.ceil(rsx), Math.ceil(rsy), Math.floor(sw), Math.floor(sh)), path => Quickshell.execDetached(["swappy", "-f", path]));
closeAnim.start();
}
anchors.fill: parent anchors.fill: parent
opacity: 0 opacity: 0
hoverEnabled: true hoverEnabled: true
@ -103,8 +110,13 @@ MouseArea {
if (closeAnim.running) if (closeAnim.running)
return; return;
Quickshell.execDetached(["sh", "-c", `grim -l 0 -g '${screen.x + Math.ceil(rsx)},${screen.y + Math.ceil(rsy)} ${Math.floor(sw)}x${Math.floor(sh)}' - | swappy -f -`]); if (root.loader.freeze) {
closeAnim.start(); save();
} else {
overlay.visible = border.visible = false;
screencopy.visible = false;
screencopy.active = true;
}
} }
onPositionChanged: event => { onPositionChanged: event => {
@ -188,6 +200,8 @@ MouseArea {
} }
Loader { Loader {
id: screencopy
anchors.fill: parent anchors.fill: parent
active: root.loader.freeze active: root.loader.freeze
@ -195,10 +209,19 @@ MouseArea {
sourceComponent: ScreencopyView { sourceComponent: ScreencopyView {
captureSource: root.screen captureSource: root.screen
onHasContentChanged: {
if (hasContent && !root.loader.freeze) {
overlay.visible = border.visible = true;
root.save();
}
}
} }
} }
StyledRect { StyledRect {
id: overlay
anchors.fill: parent anchors.fill: parent
color: Colours.palette.m3secondaryContainer color: Colours.palette.m3secondaryContainer
opacity: 0.3 opacity: 0.3
@ -232,6 +255,8 @@ MouseArea {
} }
Rectangle { Rectangle {
id: border
color: "transparent" color: "transparent"
radius: root.realRounding > 0 ? root.realRounding + root.realBorderWidth : 0 radius: root.realRounding > 0 ? root.realRounding + root.realBorderWidth : 0
border.width: root.realBorderWidth border.width: root.realBorderWidth

View file

@ -11,7 +11,6 @@
cava, cava,
networkmanager, networkmanager,
lm_sensors, lm_sensors,
grim,
swappy, swappy,
wl-clipboard, wl-clipboard,
libqalculate, libqalculate,
@ -46,7 +45,6 @@
cava cava
networkmanager networkmanager
lm_sensors lm_sensors
grim
swappy swappy
wl-clipboard wl-clipboard
libqalculate libqalculate