Skip to content

Commit b49511c

Browse files
authored
Merge pull request #18 from JDKamalakar/Testing
Refactor global variable handling and enhance settings page
2 parents db215a7 + 40d63ef commit b49511c

4 files changed

Lines changed: 164 additions & 20 deletions

File tree

CaptureToolbar.qml

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ PluginComponent {
6363
property real recPillDragStartPillX: 0
6464
property real recPillDragStartPillY: 0
6565
property bool recPillDragStarted: false
66+
property bool _isSavingDrag: false
6667
readonly property int recPillWindowWidth: 460
6768
readonly property int recPillWindowHeight: 60
6869

@@ -114,7 +115,6 @@ PluginComponent {
114115
root.settingsExpanded = false;
115116
root.delayExpanded = false;
116117
overlay.visible = true;
117-
overlay.forceActiveFocus();
118118
}
119119

120120
function close() {
@@ -128,17 +128,22 @@ PluginComponent {
128128
else root.open();
129129
}
130130

131+
132+
131133
function _save(key, value) {
132-
if (typeof PluginService !== "undefined" && PluginService) {
133-
PluginService.savePluginData("screenCaptureToolbar", key, value);
134-
PluginService.setGlobalVar("screenCaptureToolbar", key, value);
134+
if (root.pluginService) {
135+
root.pluginService.savePluginData("screenCaptureToolbar", key, value);
136+
root.pluginService.setGlobalVar("screenCaptureToolbar", key, value);
135137
}
136138
}
137139

138140
Connections {
139-
target: PluginService
140-
function onGlobalVarChanged(plugin, key, value) {
141-
if (plugin === "screenCaptureToolbar") {
141+
target: root.pluginService
142+
function onGlobalVarChanged(plugin, key) {
143+
if (plugin === "screenCaptureToolbar" && root.pluginService) {
144+
const value = root.pluginService.getGlobalVar(plugin, key, undefined);
145+
if (value === undefined) return;
146+
142147
if (key === "copyToClipboard") root.copyToClipboard = value;
143148
else if (key === "saveToDisk") root.saveToDisk = value;
144149
else if (key === "stdout") root.stdout = value;
@@ -256,6 +261,7 @@ PluginComponent {
256261
}
257262

258263
function endRecPillDrag() {
264+
root._isSavingDrag = true;
259265
root.recPillDragging = false;
260266
root.recPillDragStarted = false;
261267

@@ -278,6 +284,7 @@ PluginComponent {
278284
root._save("recPillX", root.recPillX);
279285
root._save("recPillY", root.recPillY);
280286
}
287+
root._isSavingDrag = false;
281288
}
282289

283290
function ensureRecPillScreen() {
@@ -345,9 +352,11 @@ PluginComponent {
345352
root.toolbarOpacity = pluginData.toolbarOpacity !== undefined ? pluginData.toolbarOpacity : 0.85;
346353
root.pillOpacity = pluginData.pillOpacity !== undefined ? pluginData.pillOpacity : 0.92;
347354

348-
if (pluginData.recPillScreenName !== undefined) root.recPillScreenName = pluginData.recPillScreenName;
349-
if (pluginData.recPillX !== undefined) root.recPillX = pluginData.recPillX;
350-
if (pluginData.recPillY !== undefined) root.recPillY = pluginData.recPillY;
355+
if (!root._isSavingDrag) {
356+
if (pluginData.recPillScreenName !== undefined) root.recPillScreenName = pluginData.recPillScreenName;
357+
if (pluginData.recPillX !== undefined) root.recPillX = pluginData.recPillX;
358+
if (pluginData.recPillY !== undefined) root.recPillY = pluginData.recPillY;
359+
}
351360
}
352361

353362
function performCapture(forceEdit = false) {
@@ -356,8 +365,8 @@ PluginComponent {
356365
return;
357366
}
358367

359-
// Apply delay only for non-interactive screenshot modes
360-
let useDelay = !root.isVideoMode && root.captureMode !== "interactive" && root.delaySeconds > 0;
368+
// Apply delay for screenshot modes
369+
let useDelay = !root.isVideoMode && root.delaySeconds > 0;
361370

362371
if (useDelay) {
363372
root.close(); // Close immediately so it's not in the shot
@@ -527,12 +536,28 @@ PluginComponent {
527536
"if command -v slurp >/dev/null 2>&1; then " +
528537
"REGION=$(slurp -f '%wx%h+%x+%y') || { cancel_rec; exit 1; }; " +
529538
"[ -z \"$REGION\" ] && { cancel_rec; exit 1; }; " +
530-
"start_rec; gpu-screen-recorder -w region -region \"$REGION\"" + gsrSuffix + "; " +
539+
"start_rec; exec gpu-screen-recorder -w region -region \"$REGION\"" + gsrSuffix + "; " +
540+
"else " +
541+
"start_rec; exec gpu-screen-recorder -w portal" + gsrSuffix + "; " +
542+
"fi";
543+
} else if (root.captureMode === "all") {
544+
scriptBody = "sleep 0.2; mkdir -p \"" + dir + "\"; " +
545+
"HAS_PORTAL=\"\"; " +
546+
"if command -v dbus-send >/dev/null 2>&1; then " +
547+
"dbus-send --dest=org.freedesktop.portal.Desktop --print-reply /org/freedesktop/portal/desktop org.freedesktop.DBus.Introspectable.Introspect 2>/dev/null | grep -q \"org.freedesktop.portal.ScreenCast\" && HAS_PORTAL=\"1\"; " +
548+
"elif command -v busctl >/dev/null 2>&1; then " +
549+
"busctl introspect org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop 2>/dev/null | grep -q \"org.freedesktop.portal.ScreenCast\" && HAS_PORTAL=\"1\"; " +
550+
"fi; " +
551+
"if [ -n \"$HAS_PORTAL\" ] && { [ \"$XDG_SESSION_TYPE\" = \"wayland\" ] || [ -n \"$WAYLAND_DISPLAY\" ]; }; then " +
552+
"exec gpu-screen-recorder -w portal" + gsrSuffix + "; " +
553+
"elif [ \"$XDG_SESSION_TYPE\" = \"wayland\" ] || [ -n \"$WAYLAND_DISPLAY\" ]; then " +
554+
"notify-send \"Multi-Monitor Recording\" \"Recording focused screen. Install a desktop portal (e.g. xdg-desktop-portal-niri) to record all screens on Wayland.\" -t 5000; " +
555+
"exec gpu-screen-recorder -w \"$MONITOR\"" + gsrSuffix + "; " +
531556
"else " +
532-
"start_rec; gpu-screen-recorder -w portal" + gsrSuffix + "; " +
557+
"exec gpu-screen-recorder -w screen" + gsrSuffix + "; " +
533558
"fi";
534559
} else {
535-
scriptBody = "sleep 0.2; mkdir -p \"" + dir + "\"; gpu-screen-recorder -w \"$MONITOR\"" + gsrSuffix;
560+
scriptBody = "sleep 0.2; mkdir -p \"" + dir + "\"; exec gpu-screen-recorder -w \"$MONITOR\"" + gsrSuffix;
536561
}
537562

538563
let finalCmd = prelude !== "" ? prelude + "; " + scriptBody : scriptBody;
@@ -553,7 +578,7 @@ PluginComponent {
553578
}
554579

555580
function stopRecording() {
556-
Quickshell.execDetached(["pkill", "-SIGINT", "-f", "^gpu-screen-recorder"]);
581+
Quickshell.execDetached(["pkill", "-SIGINT", "-f", "gpu-screen-recorder"]);
557582
Quickshell.execDetached(["pactl", "set-source-mute", "@DEFAULT_SOURCE@", "0"]);
558583
root.isRecording = false;
559584
root.isPaused = false;
@@ -567,12 +592,12 @@ PluginComponent {
567592
}
568593

569594
function pauseRecording() {
570-
Quickshell.execDetached(["pkill", "-SIGUSR2", "-f", "^gpu-screen-recorder"]);
595+
Quickshell.execDetached(["pkill", "-SIGUSR2", "-f", "gpu-screen-recorder"]);
571596
root.isPaused = true;
572597
}
573598

574599
function resumeRecording() {
575-
Quickshell.execDetached(["pkill", "-SIGUSR2", "-f", "^gpu-screen-recorder"]);
600+
Quickshell.execDetached(["pkill", "-SIGUSR2", "-f", "gpu-screen-recorder"]);
576601
root.isPaused = false;
577602
}
578603

@@ -1150,7 +1175,7 @@ PluginComponent {
11501175

11511176
ToolbarBtn {
11521177
id: delayBtn
1153-
visible: !root.isVideoMode && root.captureMode !== "interactive"
1178+
visible: !root.isVideoMode
11541179
isFirst: true
11551180
iconName: "timer"
11561181
tooltipText: "Delay: " + root.delaySeconds + "s"

CopyBox.qml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import QtQuick
2+
import qs.Common
3+
import qs.Widgets
4+
import qs.Services
5+
6+
Column {
7+
id: root
8+
width: parent.width
9+
spacing: 4
10+
11+
property string label: ""
12+
property string text: ""
13+
14+
StyledText {
15+
width: parent.width
16+
text: root.label
17+
font.pixelSize: Theme.fontSizeSmall
18+
font.bold: true
19+
color: Theme.surfaceVariantText
20+
visible: text !== ""
21+
}
22+
23+
Rectangle {
24+
width: parent.width
25+
height: Math.max(40, cmdRow.implicitHeight + 16)
26+
color: Theme.surfaceContainer
27+
radius: 4
28+
29+
Row {
30+
id: cmdRow
31+
width: parent.width - 16
32+
anchors.centerIn: parent
33+
spacing: 8
34+
35+
StyledText {
36+
width: parent.width - 32
37+
text: root.text
38+
font.family: "Monospace"
39+
font.pixelSize: Theme.fontSizeSmall
40+
color: Theme.secondary
41+
wrapMode: Text.Wrap
42+
}
43+
44+
DankButton {
45+
width: 24; height: 24
46+
iconName: "content_copy"
47+
backgroundColor: "transparent"
48+
textColor: Theme.primary
49+
anchors.verticalCenter: parent.verticalCenter
50+
onClicked: {
51+
Proc.runCommand("copy-ipc", ["wl-copy", "--", root.text], function() {
52+
ToastService.showInfo("Copied to clipboard");
53+
});
54+
}
55+
}
56+
}
57+
}
58+
}

Settings.qml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,5 +519,66 @@ PluginSettings {
519519
}
520520
}
521521
}
522+
523+
// --- Commands & Shortcuts ---
524+
Rectangle {
525+
width: parent.width
526+
height: commandsGroup.implicitHeight + Theme.spacingM * 2
527+
color: Theme.surfaceContainer
528+
radius: Theme.cornerRadius
529+
border.color: Theme.outline
530+
border.width: 1
531+
opacity: 0.8
532+
533+
Column {
534+
id: commandsGroup
535+
anchors.fill: parent
536+
anchors.margins: Theme.spacingM
537+
spacing: Theme.spacingM
538+
539+
Row {
540+
width: parent.width; spacing: Theme.spacingM
541+
DankIcon { name: "terminal"; size: 22; anchors.verticalCenter: parent.verticalCenter; opacity: 0.8 }
542+
StyledText { text: "Commands & Shortcuts"; font.pixelSize: Theme.fontSizeMedium; font.weight: Font.Medium; color: Theme.surfaceText; anchors.verticalCenter: parent.verticalCenter }
543+
}
544+
545+
StyledText {
546+
width: parent.width
547+
text: "You can open, close, or toggle the screen capture toolbar using the dms CLI:"
548+
font.pixelSize: Theme.fontSizeSmall
549+
color: Theme.surfaceVariantText
550+
wrapMode: Text.WordWrap
551+
}
552+
553+
CopyBox {
554+
label: "Toggle Toolbar Command"
555+
text: "dms ipc call screenCaptureToolbar toggle"
556+
}
557+
558+
CopyBox {
559+
label: "Open Toolbar Command"
560+
text: "dms ipc call screenCaptureToolbar open"
561+
}
562+
563+
CopyBox {
564+
label: "Close Toolbar Command"
565+
text: "dms ipc call screenCaptureToolbar close"
566+
}
567+
568+
StyledText {
569+
width: parent.width
570+
text: "To trigger the screen capture toolbar using Print Screen, add this spawn command to your Niri configuration binds:"
571+
font.pixelSize: Theme.fontSizeSmall
572+
color: Theme.primary
573+
font.italic: true
574+
wrapMode: Text.WordWrap
575+
}
576+
577+
CopyBox {
578+
label: "Niri Bind Configuration"
579+
text: "Print { spawn \"dms\" \"ipc\" \"call\" \"screenCaptureToolbar\" \"toggle\"; }"
580+
}
581+
}
582+
}
522583
}
523584
}

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Screen Capture Toolbar",
44
"description": "Premium pill-shaped toolbar for quick screenshots and screen recording",
55
"category": "utilities",
6-
"version": "1.3.3",
6+
"version": "1.3.4",
77
"author": "JDKamalakar",
88
"icon": "screenshot_region",
99
"type": "daemon",

0 commit comments

Comments
 (0)