diff options
| author | Danilo M. <danix@danix.xyz> | 2026-10-07 18:51:01 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-10-07 18:51:01 +0200 |
| commit | e005e2237c3c3ea7dab7e1059c7432245903959c (patch) | |
| tree | 1ebdaacfdecd646e18b7485a3c48e00731e2fdf3 /desktop | |
| parent | ab3fa11a4b0a5e2dc999d91d98269b3204f0aaa3 (diff) | |
| download | quickshell-e005e2237c3c3ea7dab7e1059c7432245903959c.tar.gz quickshell-e005e2237c3c3ea7dab7e1059c7432245903959c.zip | |
feat(island): privacy detection for mic, camera, location, screen
Ported from waybar-theme-udt's privacy_dots.sh, because the island's sliver
takes over that indicator when waybar goes. pw-dump stays for mic and
screen: PwNode has no running state to tell capture from an idle source.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop')
| -rw-r--r-- | desktop/island/Privacy.qml | 57 | ||||
| -rwxr-xr-x | desktop/island/privacy.sh | 39 |
2 files changed, 96 insertions, 0 deletions
diff --git a/desktop/island/Privacy.qml b/desktop/island/Privacy.qml new file mode 100644 index 0000000..c09a8d1 --- /dev/null +++ b/desktop/island/Privacy.qml @@ -0,0 +1,57 @@ +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +pragma Singleton + +import Quickshell +import Quickshell.Io +import QtQuick +import "Logic.js" as Logic + +// What is capturing: microphone, camera, location, screen. Polled every 2s +// from privacy.sh, the same cadence class as the waybar module it replaces. +Singleton { + id: root + + property bool mic: false + property bool cam: false + property bool loc: false + property bool scr: false + + // Theme property names of the active kinds, fixed order. + readonly property var roles: Logic.privacyRoles(mic, cam, loc, scr) + + Process { + id: proc + command: ["sh", `${Quickshell.shellDir}/island/privacy.sh`] + stdout: StdioCollector { + onStreamFinished: { + const b = text.trim().split(" "); + // Anything but four fields is a broken run, not "nothing is + // capturing": keep the last good reading. + if (b.length !== 4) return; + root.mic = b[0] === "1"; + root.cam = b[1] === "1"; + root.loc = b[2] === "1"; + root.scr = b[3] === "1"; + } + } + } + + Timer { + interval: 2000 + running: true + repeat: true + triggeredOnStart: true + // A Process already running ignores running = true (AGENTS.md). + onTriggered: { proc.running = false; proc.running = true; } + } +} diff --git a/desktop/island/privacy.sh b/desktop/island/privacy.sh new file mode 100755 index 0000000..9d5b360 --- /dev/null +++ b/desktop/island/privacy.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# +# Copyright (C) 2026 Danilo M. <danix@danix.xyz> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# One line, "mic cam loc scr", each 0 or 1: what is capturing right now. +# The rules are waybar-theme-udt's privacy_dots.sh. Mic and screen need +# pw-dump because a capturing source is told from an idle one by its node +# state, which Quickshell's PwNode does not expose. + +dump=$(pw-dump 2>/dev/null) + +mic=$(printf '%s' "$dump" | jq '[.[] + | select(.type == "PipeWire:Interface:Node") + | select(.info.props["media.class"] == "Audio/Source" + or .info.props["media.class"] == "Audio/Source/Virtual") + | select(.info.state == "running")] | if length > 0 then 1 else 0 end' 2>/dev/null) + +scr=$(printf '%s' "$dump" | jq '[.[] + | select((.info?.props?["media.name"]? // "") | test("^(xdph-streaming|gsr-default)"))] + | if length > 0 then 1 else 0 end' 2>/dev/null) + +cam=0 +for dev in /dev/video*; do + [ -e "$dev" ] && fuser "$dev" >/dev/null 2>&1 && { cam=1; break; } +done + +loc=0 +pgrep -x geoclue >/dev/null 2>&1 && loc=1 + +echo "${mic:-0} $cam $loc ${scr:-0}" |
