Add Night Light bar indicator
This commit is contained in:
@@ -1,22 +1,48 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# omarchy:summary=Toggle nightlight screen temperature
|
# omarchy:summary=Toggle nightlight screen temperature
|
||||||
|
# omarchy:args=[--status]
|
||||||
# omarchy:examples=omarchy toggle nightlight
|
# omarchy:examples=omarchy toggle nightlight
|
||||||
|
|
||||||
ON_TEMP=4000
|
ON_TEMP=4000
|
||||||
OFF_TEMP=6000
|
OFF_TEMP=6000
|
||||||
|
|
||||||
|
current_temp() {
|
||||||
|
hyprctl hyprsunset temperature 2>/dev/null | grep -oE '[0-9]+' | head -n1
|
||||||
|
}
|
||||||
|
|
||||||
|
status_json() {
|
||||||
|
local temp enabled
|
||||||
|
|
||||||
|
temp=$(current_temp)
|
||||||
|
if [[ -n $temp && $temp != $OFF_TEMP ]]; then
|
||||||
|
enabled=true
|
||||||
|
else
|
||||||
|
enabled=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
jq -cn --argjson enabled "$enabled" --arg temp "$temp" \
|
||||||
|
'{enabled:$enabled, temperature:(($temp | tonumber?) // null)}'
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ ${1:-} == "--status" ]]; then
|
||||||
|
status_json
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Ensure hyprsunset is running
|
# Ensure hyprsunset is running
|
||||||
if ! pgrep -x hyprsunset; then
|
if ! pgrep -x hyprsunset >/dev/null; then
|
||||||
setsid uwsm-app -- hyprsunset &
|
setsid uwsm-app -- hyprsunset &
|
||||||
sleep 1 # Give it time to register
|
sleep 1 # Give it time to register
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Query the current temperature
|
# Query the current temperature
|
||||||
CURRENT_TEMP=$(hyprctl hyprsunset temperature 2>/dev/null | grep -oE '[0-9]+')
|
CURRENT_TEMP=$(current_temp)
|
||||||
|
|
||||||
if [[ $CURRENT_TEMP == $OFF_TEMP ]]; then
|
if [[ $CURRENT_TEMP == $OFF_TEMP ]]; then
|
||||||
hyprctl hyprsunset temperature $ON_TEMP
|
hyprctl hyprsunset temperature $ON_TEMP
|
||||||
else
|
else
|
||||||
hyprctl hyprsunset temperature $OFF_TEMP
|
hyprctl hyprsunset temperature $OFF_TEMP
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
omarchy-shell -q bar refreshIndicators >/dev/null 2>&1 || true
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
echo "Add Night Light to the default bar indicator list"
|
||||||
|
|
||||||
|
config_file="$HOME/.config/omarchy/shell.json"
|
||||||
|
|
||||||
|
if [[ -f $config_file ]] && omarchy-cmd-present jq; then
|
||||||
|
tmp=$(mktemp)
|
||||||
|
jq '
|
||||||
|
def indicator_id:
|
||||||
|
if type == "string" then
|
||||||
|
.
|
||||||
|
elif type == "object" then
|
||||||
|
(.id // "")
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end;
|
||||||
|
|
||||||
|
def has_indicator($id):
|
||||||
|
any(.[]?; indicator_id == $id);
|
||||||
|
|
||||||
|
def indicator_index($id):
|
||||||
|
[range(0; length) as $i | select((.[$i] | indicator_id) == $id) | $i][0];
|
||||||
|
|
||||||
|
def nightlight_entry:
|
||||||
|
if any(.[]?; type == "object") then
|
||||||
|
{ id: "nightlight" }
|
||||||
|
else
|
||||||
|
"nightlight"
|
||||||
|
end;
|
||||||
|
|
||||||
|
def add_nightlight:
|
||||||
|
if type != "array" or has_indicator("nightlight") then
|
||||||
|
.
|
||||||
|
else
|
||||||
|
(indicator_index("dnd")) as $dnd_index |
|
||||||
|
if $dnd_index == null then
|
||||||
|
.
|
||||||
|
else
|
||||||
|
.[0:$dnd_index + 1] + [nightlight_entry] + .[$dnd_index + 1:]
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
|
||||||
|
.bar.layout |= (
|
||||||
|
if type == "object" then
|
||||||
|
with_entries(
|
||||||
|
.value |= (
|
||||||
|
if type == "array" then
|
||||||
|
map(
|
||||||
|
if type == "object" and .id == "indicators" then
|
||||||
|
if (.items | type) == "array" then
|
||||||
|
.items |= add_nightlight
|
||||||
|
elif (.indicators | type) == "array" then
|
||||||
|
.indicators |= add_nightlight
|
||||||
|
else
|
||||||
|
.
|
||||||
|
end
|
||||||
|
else
|
||||||
|
.
|
||||||
|
end
|
||||||
|
)
|
||||||
|
else
|
||||||
|
.
|
||||||
|
end
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else
|
||||||
|
.
|
||||||
|
end
|
||||||
|
)
|
||||||
|
' "$config_file" >"$tmp" && mv "$tmp" "$config_file" || rm -f "$tmp"
|
||||||
|
fi
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import QtQuick
|
||||||
|
import Quickshell.Io
|
||||||
|
import qs.Ui
|
||||||
|
|
||||||
|
BarIndicator {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property bool nightlight: false
|
||||||
|
|
||||||
|
active: nightlight
|
||||||
|
activeText: ""
|
||||||
|
inactiveText: ""
|
||||||
|
activeTooltipText: "Night Light on"
|
||||||
|
inactiveTooltipText: "Night Light"
|
||||||
|
|
||||||
|
function refresh() {
|
||||||
|
if (!statusProc.running) statusProc.running = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function update(raw) {
|
||||||
|
var data = extractData(raw)
|
||||||
|
nightlight = data && data.enabled === true
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggle() {
|
||||||
|
if (root.bar) root.bar.run("omarchy-toggle-nightlight")
|
||||||
|
refreshTimer.restart()
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: refresh()
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: root.bar
|
||||||
|
ignoreUnknownSignals: true
|
||||||
|
function onIndicatorsRefreshRequested() { root.refresh() }
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: statusProc
|
||||||
|
command: ["omarchy-toggle-nightlight", "--status"]
|
||||||
|
stdout: StdioCollector {
|
||||||
|
waitForEnd: true
|
||||||
|
onStreamFinished: root.update(text)
|
||||||
|
}
|
||||||
|
onExited: function(exitCode) {
|
||||||
|
if (exitCode !== 0) root.nightlight = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: refreshTimer
|
||||||
|
interval: 1500
|
||||||
|
onTriggered: root.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 5000
|
||||||
|
running: true
|
||||||
|
repeat: true
|
||||||
|
onTriggered: root.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
onPressed: function() { root.toggle() }
|
||||||
|
}
|
||||||
@@ -133,7 +133,7 @@ Item {
|
|||||||
left: [{ id: "omarchy" }, { id: "workspaces" }],
|
left: [{ id: "omarchy" }, { id: "workspaces" }],
|
||||||
center: [
|
center: [
|
||||||
{ id: "calendar", format: "dddd HH:mm", formatAlt: "dd MMMM 'W'ww yyyy", verticalFormat: "HH\n\u2014\nmm" },
|
{ id: "calendar", format: "dddd HH:mm", formatAlt: "dd MMMM 'W'ww yyyy", verticalFormat: "HH\n\u2014\nmm" },
|
||||||
{ id: "weather" }, { id: "indicators", items: [ "dnd", "stayAwake", "screenrecording", "dictation" ] }, { id: "update" }
|
{ id: "weather" }, { id: "indicators", items: [ "dnd", "nightlight", "stayAwake", "screenrecording", "dictation" ] }, { id: "update" }
|
||||||
],
|
],
|
||||||
right: [
|
right: [
|
||||||
{ id: "tray" }, { id: "bluetoothPanel" }, { id: "networkPanel" },
|
{ id: "tray" }, { id: "bluetoothPanel" }, { id: "networkPanel" },
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
"id": "indicators",
|
"id": "indicators",
|
||||||
"items": [
|
"items": [
|
||||||
"dnd",
|
"dnd",
|
||||||
|
"nightlight",
|
||||||
"stayAwake",
|
"stayAwake",
|
||||||
"screenrecording",
|
"screenrecording",
|
||||||
"dictation"
|
"dictation"
|
||||||
|
|||||||
Reference in New Issue
Block a user