add location and do not disturb toggles
This commit is contained in:
parent
b5e5ecf2f3
commit
518ffa31b4
8 changed files with 263 additions and 3 deletions
15
README.md
15
README.md
|
|
@ -10,6 +10,9 @@ The bar shows the time, cellular, Wi-Fi, Bluetooth and battery. The sheet has:
|
||||||
|
|
||||||
- Wi-Fi, Bluetooth, cellular and mobile data toggles. The arrow on Wi-Fi opens `nmgui`, and on
|
- Wi-Fi, Bluetooth, cellular and mobile data toggles. The arrow on Wi-Fi opens `nmgui`, and on
|
||||||
Bluetooth it opens `adw-bluetooth`.
|
Bluetooth it opens `adw-bluetooth`.
|
||||||
|
- Location, which decides whether apps get your location through GeoClue. The bar shows an icon
|
||||||
|
while one is using it.
|
||||||
|
- Do not disturb, which stops notifications popping up. They still go into the sheet.
|
||||||
- A flashlight
|
- A flashlight
|
||||||
- Rotation, with a choice of orientations
|
- Rotation, with a choice of orientations
|
||||||
- Screenshot and power (suspend, restart, power off) buttons
|
- Screenshot and power (suspend, restart, power off) buttons
|
||||||
|
|
@ -50,6 +53,15 @@ It brings `nmcli`, `mmcli`, `nmgui` and `adw-bluetooth` with it. The system need
|
||||||
- The Papirus-Dark icon theme and the Inter font
|
- The Papirus-Dark icon theme and the Inter font
|
||||||
- An on-screen keyboard that uses text-input-v3, like Stevia, to type the password
|
- An on-screen keyboard that uses text-input-v3, like Stevia, to type the password
|
||||||
- No other notification daemon, like swaync or mako, as only one can run at a time
|
- No other notification daemon, like swaync or mako, as only one can run at a time
|
||||||
|
- GeoClue, with quadshell as its agent, for the location toggle:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
services.geoclue2 = {
|
||||||
|
enable = true;
|
||||||
|
enableDemoAgent = false;
|
||||||
|
whitelistedAgents = [ "quadshell" ];
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
## Developing
|
## Developing
|
||||||
|
|
||||||
|
|
@ -60,7 +72,8 @@ nix run .#phone [host]
|
||||||
This copies `src` to the phone over SSH (`host` defaults to `phone`) and runs it there, showing
|
This copies `src` to the phone over SSH (`host` defaults to `phone`) and runs it there, showing
|
||||||
its logs until you press Ctrl+C. It stops any other running Quickshell first, so when you quit
|
its logs until you press Ctrl+C. It stops any other running Quickshell first, so when you quit
|
||||||
there's no bar until you run it again. The phone needs Quickshell from this flake's nixpkgs
|
there's no bar until you run it again. The phone needs Quickshell from this flake's nixpkgs
|
||||||
already in its store, as it doesn't download anything.
|
already in its store. The location agent gets built on the phone, from things this machine copies
|
||||||
|
over, so the phone doesn't need to download anything.
|
||||||
|
|
||||||
### Editor support
|
### Editor support
|
||||||
|
|
||||||
|
|
|
||||||
13
flake.nix
13
flake.nix
|
|
@ -26,6 +26,11 @@
|
||||||
quickshell = builtins.unsafeDiscardStringContext (
|
quickshell = builtins.unsafeDiscardStringContext (
|
||||||
nixpkgs.lib.getExe nixpkgs.legacyPackages.aarch64-linux.quickshell
|
nixpkgs.lib.getExe nixpkgs.legacyPackages.aarch64-linux.quickshell
|
||||||
);
|
);
|
||||||
|
# This one isn't in the cache, so its derivation is copied over and the phone builds it
|
||||||
|
locationAgent =
|
||||||
|
(nixpkgs.legacyPackages.aarch64-linux.extend self.overlays.default).quadshell.locationAgent;
|
||||||
|
agentDrv = builtins.unsafeDiscardOutputDependency locationAgent.drvPath;
|
||||||
|
agentBin = "${builtins.unsafeDiscardStringContext locationAgent.outPath}/bin";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# nix run .#phone [host]: runs the shell on the phone until Ctrl+C.
|
# nix run .#phone [host]: runs the shell on the phone until Ctrl+C.
|
||||||
|
|
@ -42,6 +47,11 @@
|
||||||
host=''${1:-phone}
|
host=''${1:-phone}
|
||||||
dest=.cache/quadshell-dev
|
dest=.cache/quadshell-dev
|
||||||
|
|
||||||
|
mapfile -t inputs < <(nix-store --query --references ${agentDrv} | grep '\.drv$')
|
||||||
|
nix-store --realise "''${inputs[@]}" >/dev/null
|
||||||
|
nix copy --derivation --to "ssh-ng://$host" ${agentDrv}
|
||||||
|
nix copy --to "ssh-ng://$host" "''${inputs[@]/%/^*}"
|
||||||
|
|
||||||
# The store's files are read-only, which would stop the next run replacing them
|
# The store's files are read-only, which would stop the next run replacing them
|
||||||
# shellcheck disable=SC2029
|
# shellcheck disable=SC2029
|
||||||
tar -C ${self}/src --mode=u+w -c . | ssh "$host" "rm -rf $dest; mkdir -p $dest; tar -C $dest -x"
|
tar -C ${self}/src --mode=u+w -c . | ssh "$host" "rm -rf $dest; mkdir -p $dest; tar -C $dest -x"
|
||||||
|
|
@ -49,8 +59,9 @@
|
||||||
# shellcheck disable=SC2029
|
# shellcheck disable=SC2029
|
||||||
exec ssh -t "$host" "
|
exec ssh -t "$host" "
|
||||||
nix-store --realise ${builtins.dirOf (builtins.dirOf quickshell)} >/dev/null;
|
nix-store --realise ${builtins.dirOf (builtins.dirOf quickshell)} >/dev/null;
|
||||||
|
nix-store --realise --option substitute false ${agentDrv} >/dev/null;
|
||||||
pkill -f '^/nix/store/[^ ]*/bin/quickshell ';
|
pkill -f '^/nix/store/[^ ]*/bin/quickshell ';
|
||||||
exec systemd-run --user --pty --quiet --collect ${quickshell} --path ~/$dest
|
exec systemd-run --user --pty --quiet --collect --setenv=PATH=${agentBin}:\"\$PATH\" ${quickshell} --path ~/$dest
|
||||||
"
|
"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
159
location-agent.js
Normal file
159
location-agent.js
Normal file
|
|
@ -0,0 +1,159 @@
|
||||||
|
import Gio from "gi://Gio"
|
||||||
|
import GioUnix from "gi://GioUnix"
|
||||||
|
import GLib from "gi://GLib"
|
||||||
|
|
||||||
|
const AGENT_ID = "quadshell"
|
||||||
|
const AGENT_PATH = "/org/freedesktop/GeoClue2/Agent"
|
||||||
|
const GEOCLUE = "org.freedesktop.GeoClue2"
|
||||||
|
const MANAGER = `${GEOCLUE}.Manager`
|
||||||
|
const MANAGER_PATH = "/org/freedesktop/GeoClue2/Manager"
|
||||||
|
const ACCURACY_NONE = 0
|
||||||
|
const ACCURACY_EXACT = 8
|
||||||
|
|
||||||
|
const INTERFACE = `
|
||||||
|
<node>
|
||||||
|
<interface name="org.freedesktop.GeoClue2.Agent">
|
||||||
|
<method name="AuthorizeApp">
|
||||||
|
<arg name="desktop_id" type="s" direction="in"/>
|
||||||
|
<arg name="req_accuracy_level" type="u" direction="in"/>
|
||||||
|
<arg name="authorized" type="b" direction="out"/>
|
||||||
|
<arg name="allowed_accuracy_level" type="u" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<property name="MaxAccuracyLevel" type="u" access="read"/>
|
||||||
|
</interface>
|
||||||
|
</node>`
|
||||||
|
|
||||||
|
const stateDir = GLib.build_filenamev([GLib.get_user_state_dir(), "quadshell"])
|
||||||
|
const stateFile = GLib.build_filenamev([stateDir, "location"])
|
||||||
|
|
||||||
|
let enabled = true
|
||||||
|
try {
|
||||||
|
const [, contents] = GLib.file_get_contents(stateFile)
|
||||||
|
enabled = new TextDecoder().decode(contents).trim() !== "off"
|
||||||
|
} catch {
|
||||||
|
// Not set yet
|
||||||
|
}
|
||||||
|
|
||||||
|
const bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, null)
|
||||||
|
const loop = new GLib.MainLoop(null, false)
|
||||||
|
|
||||||
|
const stdout = new Gio.DataOutputStream({
|
||||||
|
base_stream: new GioUnix.OutputStream({ fd: 1 }),
|
||||||
|
})
|
||||||
|
|
||||||
|
function report(key, value) {
|
||||||
|
stdout.put_string(`${key} ${value ? 1 : 0}\n`, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxAccuracy = () => (enabled ? ACCURACY_EXACT : ACCURACY_NONE)
|
||||||
|
|
||||||
|
const agent = Gio.DBusExportedObject.wrapJSObject(INTERFACE, {
|
||||||
|
AuthorizeApp(_desktopId, requested) {
|
||||||
|
return [enabled, Math.min(requested, maxAccuracy())]
|
||||||
|
},
|
||||||
|
get MaxAccuracyLevel() {
|
||||||
|
return maxAccuracy()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function setEnabled(on) {
|
||||||
|
if (on !== enabled) {
|
||||||
|
enabled = on
|
||||||
|
GLib.mkdir_with_parents(stateDir, 0o755)
|
||||||
|
GLib.file_set_contents(stateFile, on ? "on" : "off")
|
||||||
|
agent.emit_property_changed(
|
||||||
|
"MaxAccuracyLevel",
|
||||||
|
GLib.Variant.new_uint32(maxAccuracy()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
report("enabled", enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onGeoclueAppeared() {
|
||||||
|
bus.call(
|
||||||
|
GEOCLUE,
|
||||||
|
MANAGER_PATH,
|
||||||
|
MANAGER,
|
||||||
|
"AddAgent",
|
||||||
|
new GLib.Variant("(s)", [AGENT_ID]),
|
||||||
|
null,
|
||||||
|
Gio.DBusCallFlags.NONE,
|
||||||
|
-1,
|
||||||
|
null,
|
||||||
|
(conn, result) => {
|
||||||
|
try {
|
||||||
|
conn.call_finish(result)
|
||||||
|
} catch (e) {
|
||||||
|
printerr(
|
||||||
|
`GeoClue didn't accept the agent, is ${AGENT_ID} in its whitelist? ${e.message}`,
|
||||||
|
)
|
||||||
|
report("available", false)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
bus.call(
|
||||||
|
GEOCLUE,
|
||||||
|
MANAGER_PATH,
|
||||||
|
"org.freedesktop.DBus.Properties",
|
||||||
|
"Get",
|
||||||
|
new GLib.Variant("(ss)", [MANAGER, "InUse"]),
|
||||||
|
new GLib.VariantType("(v)"),
|
||||||
|
Gio.DBusCallFlags.NONE,
|
||||||
|
-1,
|
||||||
|
null,
|
||||||
|
(conn, result) => {
|
||||||
|
try {
|
||||||
|
report("inUse", conn.call_finish(result).recursiveUnpack()[0])
|
||||||
|
} catch {
|
||||||
|
// It went away again
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const stdin = new Gio.DataInputStream({
|
||||||
|
base_stream: new GioUnix.InputStream({ fd: 0 }),
|
||||||
|
})
|
||||||
|
|
||||||
|
function readLine() {
|
||||||
|
stdin.read_line_async(GLib.PRIORITY_DEFAULT, null, (stream, result) => {
|
||||||
|
const [line] = stream.read_line_finish_utf8(result)
|
||||||
|
if (line === null) {
|
||||||
|
loop.quit()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (line.trim() === "on" || line.trim() === "off")
|
||||||
|
setEnabled(line.trim() === "on")
|
||||||
|
readLine()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
agent.export(bus, AGENT_PATH)
|
||||||
|
|
||||||
|
bus.signal_subscribe(
|
||||||
|
GEOCLUE,
|
||||||
|
"org.freedesktop.DBus.Properties",
|
||||||
|
"PropertiesChanged",
|
||||||
|
MANAGER_PATH,
|
||||||
|
MANAGER,
|
||||||
|
Gio.DBusSignalFlags.NONE,
|
||||||
|
(_conn, _sender, _path, _interface, _signal, params) => {
|
||||||
|
const [, changed] = params.recursiveUnpack()
|
||||||
|
if ("InUse" in changed) report("inUse", changed.InUse)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
Gio.bus_watch_name_on_connection(
|
||||||
|
bus,
|
||||||
|
GEOCLUE,
|
||||||
|
Gio.BusNameWatcherFlags.NONE,
|
||||||
|
onGeoclueAppeared,
|
||||||
|
() => report("inUse", false),
|
||||||
|
)
|
||||||
|
|
||||||
|
readLine()
|
||||||
|
|
||||||
|
report("enabled", enabled)
|
||||||
|
report("available", true)
|
||||||
|
loop.run()
|
||||||
12
package.nix
12
package.nix
|
|
@ -2,6 +2,7 @@
|
||||||
lib,
|
lib,
|
||||||
quickshell,
|
quickshell,
|
||||||
writeShellApplication,
|
writeShellApplication,
|
||||||
|
gjs,
|
||||||
glib,
|
glib,
|
||||||
networkmanager,
|
networkmanager,
|
||||||
modemmanager,
|
modemmanager,
|
||||||
|
|
@ -17,6 +18,13 @@ let
|
||||||
root = ./src;
|
root = ./src;
|
||||||
fileset = ./src;
|
fileset = ./src;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
locationAgent = writeShellApplication {
|
||||||
|
name = "quadshell-location-agent";
|
||||||
|
text = ''
|
||||||
|
exec ${lib.getExe' gjs "gjs"} -m ${./location-agent.js} "$@"
|
||||||
|
'';
|
||||||
|
};
|
||||||
in
|
in
|
||||||
writeShellApplication {
|
writeShellApplication {
|
||||||
name = "quadshell";
|
name = "quadshell";
|
||||||
|
|
@ -31,9 +39,13 @@ writeShellApplication {
|
||||||
gnugrep
|
gnugrep
|
||||||
glib # gdbus, for logind's lock signal
|
glib # gdbus, for logind's lock signal
|
||||||
procps # pgrep, for the wallpaper swaybg is showing
|
procps # pgrep, for the wallpaper swaybg is showing
|
||||||
|
locationAgent
|
||||||
];
|
];
|
||||||
|
|
||||||
text = ''
|
text = ''
|
||||||
exec ${lib.getExe quickshell} --path ${config} "$@"
|
exec ${lib.getExe quickshell} --path ${config} "$@"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
# For nix run .#phone, which only copies src
|
||||||
|
passthru = { inherit locationAgent; };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
src/Bar.qml
12
src/Bar.qml
|
|
@ -31,6 +31,18 @@ Rectangle {
|
||||||
}
|
}
|
||||||
spacing: 6
|
spacing: 6
|
||||||
|
|
||||||
|
ShellIcon {
|
||||||
|
visible: Status.locationInUse
|
||||||
|
name: "location-services-active-symbolic"
|
||||||
|
implicitSize: 14
|
||||||
|
}
|
||||||
|
|
||||||
|
ShellIcon {
|
||||||
|
visible: Notifications.doNotDisturb
|
||||||
|
name: "notifications-disabled-symbolic"
|
||||||
|
implicitSize: 14
|
||||||
|
}
|
||||||
|
|
||||||
ShellIcon {
|
ShellIcon {
|
||||||
visible: Status.cellularEnabled
|
visible: Status.cellularEnabled
|
||||||
name: Status.cellularIcon
|
name: Status.cellularIcon
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,12 @@ Singleton {
|
||||||
readonly property var list: [...server.trackedNotifications.values].reverse() // qmllint disable missing-property
|
readonly property var list: [...server.trackedNotifications.values].reverse() // qmllint disable missing-property
|
||||||
property var popups: []
|
property var popups: []
|
||||||
property var times: ({})
|
property var times: ({})
|
||||||
|
// Notifications still go into the sheet, they just don't pop up
|
||||||
|
property bool doNotDisturb: false
|
||||||
|
|
||||||
|
onDoNotDisturbChanged: {
|
||||||
|
if (doNotDisturb) popups = [];
|
||||||
|
}
|
||||||
|
|
||||||
function hidePopup(notification) {
|
function hidePopup(notification) {
|
||||||
popups = popups.filter(n => n !== notification);
|
popups = popups.filter(n => n !== notification);
|
||||||
|
|
@ -46,7 +52,7 @@ Singleton {
|
||||||
notification.tracked = true;
|
notification.tracked = true;
|
||||||
root.times[notification.id] = new Date();
|
root.times[notification.id] = new Date();
|
||||||
notification.closed.connect(() => root.hidePopup(notification));
|
notification.closed.connect(() => root.hidePopup(notification));
|
||||||
root.popups = [notification, ...root.popups.filter(n => n !== notification)];
|
if (!root.doNotDisturb) root.popups = [notification, ...root.popups.filter(n => n !== notification)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,25 @@ Item {
|
||||||
onToggled: Status.setData(!Status.dataEnabled)
|
onToggled: Status.setData(!Status.dataEnabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Tile {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
icon: Status.location ? "location-services-active-symbolic" : "location-services-disabled-symbolic"
|
||||||
|
label: "Location"
|
||||||
|
detail: !Status.location ? "Off" : Status.locationInUse ? "In use" : "On"
|
||||||
|
available: Status.locationAvailable
|
||||||
|
active: Status.location
|
||||||
|
onToggled: Status.setLocation(!Status.location)
|
||||||
|
}
|
||||||
|
|
||||||
|
Tile {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
icon: Notifications.doNotDisturb ? "notifications-disabled-symbolic" : "notifications-symbolic"
|
||||||
|
label: "Do not disturb"
|
||||||
|
detail: Notifications.doNotDisturb ? "On" : "Off"
|
||||||
|
active: Notifications.doNotDisturb
|
||||||
|
onToggled: Notifications.doNotDisturb = !Notifications.doNotDisturb
|
||||||
|
}
|
||||||
|
|
||||||
Tile {
|
Tile {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
icon: "flashlight.svg"
|
icon: "flashlight.svg"
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@ Singleton {
|
||||||
property bool dataActive
|
property bool dataActive
|
||||||
property real cellularSignal
|
property real cellularSignal
|
||||||
property bool flashlight
|
property bool flashlight
|
||||||
|
// From quadshell-location-agent, which only comes with the package
|
||||||
|
property bool locationAvailable
|
||||||
|
property bool location
|
||||||
|
property bool locationInUse
|
||||||
property string output
|
property string output
|
||||||
property string transform: "normal"
|
property string transform: "normal"
|
||||||
|
|
||||||
|
|
@ -77,6 +81,11 @@ Singleton {
|
||||||
"sh", flashlightLed, on ? "255" : "0"]);
|
"sh", flashlightLed, on ? "255" : "0"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setLocation(on) {
|
||||||
|
location = on;
|
||||||
|
locationAgent.write(on ? "on\n" : "off\n");
|
||||||
|
}
|
||||||
|
|
||||||
function setTransform(t) {
|
function setTransform(t) {
|
||||||
if (!output) return;
|
if (!output) return;
|
||||||
transform = t;
|
transform = t;
|
||||||
|
|
@ -145,6 +154,25 @@ Singleton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: locationAgent
|
||||||
|
running: true
|
||||||
|
command: ["quadshell-location-agent"]
|
||||||
|
stdinEnabled: true
|
||||||
|
stdout: SplitParser {
|
||||||
|
onRead: line => {
|
||||||
|
const [key, value] = line.split(" ");
|
||||||
|
if (key === "enabled") root.location = value === "1";
|
||||||
|
else if (key === "inUse") root.locationInUse = value === "1";
|
||||||
|
else if (key === "available") root.locationAvailable = value === "1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onExited: {
|
||||||
|
root.locationAvailable = false;
|
||||||
|
root.locationInUse = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: refreshSoon
|
id: refreshSoon
|
||||||
interval: 400
|
interval: 400
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue