Change eww to sb
This commit is contained in:
134
status-bar/sb-battery-monitor
Executable file
134
status-bar/sb-battery-monitor
Executable file
@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env -S awk -f
|
||||
# -*- mode: awk -*-
|
||||
function get_icon(charge) {
|
||||
if (charge <= 10) {
|
||||
return "";
|
||||
} else if (charge <= 20) {
|
||||
return "";
|
||||
} else if (charge <= 30) {
|
||||
return "";
|
||||
} else if (charge <= 40) {
|
||||
return "";
|
||||
} else if (charge <= 50) {
|
||||
return "";
|
||||
} else if (charge <= 60) {
|
||||
return "";
|
||||
} else if (charge <= 70) {
|
||||
return "";
|
||||
} else if (charge <= 80) {
|
||||
return "";
|
||||
} if (charge < 100) {
|
||||
return "";
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
function notify_send(title, desc, id) {
|
||||
if (!id) {
|
||||
cmd="dunstify -t 0 -p \"" title "\" \"" desc "\""
|
||||
while ((cmd | getline id) > 0) { }
|
||||
close(cmd)
|
||||
} else {
|
||||
system("dunstify -r " id " \"" title "\" \"" desc "\"")
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
function close_notify(id) {
|
||||
system("dunstify -C " id)
|
||||
}
|
||||
|
||||
function warn_if_low() {
|
||||
percentage = state_info["percentage"]
|
||||
id = state_info["id"]
|
||||
notified = state_info["notified"]
|
||||
if (percentage <= 10) {
|
||||
if (!notified) {
|
||||
state_info["id"] = notify_send("Battery Low", percentage "%", id)
|
||||
state_info["notified"] = 1
|
||||
}
|
||||
} else if (notified) {
|
||||
close_notify(id)
|
||||
state_info["notified"] = 0
|
||||
}
|
||||
}
|
||||
|
||||
function print_state() {
|
||||
percentage = state_info["percentage"]
|
||||
tooltip = ""
|
||||
if (state_info["charging"]) {
|
||||
tooltip = "Until Full: " (percentage == 100 ? "N/A" : state_info["time to full"])
|
||||
} else {
|
||||
tooltip = "Until Empty: " state_info["time to empty"]
|
||||
}
|
||||
printf "{\"text\":\"%s%s%d%%\",\"tooltip\":\"%s\"}\n",
|
||||
get_icon(percentage),
|
||||
state_info["charging"] ? "" : "",
|
||||
percentage,
|
||||
tooltip
|
||||
fflush()
|
||||
}
|
||||
|
||||
function string_or(str, def) {
|
||||
return str == "" ? def : str
|
||||
}
|
||||
|
||||
function parse_record(record, exit_on_absent) {
|
||||
split(record, fields)
|
||||
for (i in fields) {
|
||||
match(fields[i], /^ *([^:]+): *(.+)$/, parts)
|
||||
if (length(parts) >= 3) {
|
||||
props[parts[1]] = parts[2]
|
||||
}
|
||||
}
|
||||
name = props["native-path"]
|
||||
if (name == "") {
|
||||
return 0
|
||||
} else if ((! BATTERY && props["power supply"] == "yes" && \
|
||||
props["native-path"] ~ /BAT[0-9]+/) || name == BATTERY) {
|
||||
state_info["percentage"] = props["percentage"] + 0
|
||||
state_info["time to full"] = string_or(props["time to full"], "Unknown")
|
||||
state_info["time to empty"] = string_or(props["time to empty"], "Unknown")
|
||||
return 1
|
||||
} else if ((! ADAPTER && props["power supply"] == "yes" && \
|
||||
props["native-path"] ~ /ADP[0-9]+/) || name == ADAPTER) {
|
||||
state_info["charging"] = (props["online"] == "yes")
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
function print_initial_stats() {
|
||||
cmd = "upower --dump"
|
||||
found = 0
|
||||
while ((cmd | getline record) > 0) {
|
||||
if (record ~ /Device: \/org\/freedesktop\/UPower\/devices\// \
|
||||
&& parse_record(record)) {
|
||||
found = 1
|
||||
}
|
||||
}
|
||||
close(cmd)
|
||||
if (! found) {
|
||||
# we found no battery adapters
|
||||
exit 1
|
||||
}
|
||||
print_state()
|
||||
warn_if_low()
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
RS = ""
|
||||
FS = "\n"
|
||||
print_initial_stats()
|
||||
cmd = "upower --monitor-detail"
|
||||
while ((cmd | getline record) > 0) {
|
||||
if (record ~ /device changed/) {
|
||||
parse_record(record)
|
||||
print_state()
|
||||
warn_if_low()
|
||||
}
|
||||
}
|
||||
close(cmd)
|
||||
}
|
||||
61
status-bar/sb-fcitx5-toggle
Executable file
61
status-bar/sb-fcitx5-toggle
Executable file
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env -S emacs -x
|
||||
;; -*- mode: emacs-lisp; lexical-binding: t -*-
|
||||
(require 'cl-lib)
|
||||
(require 'server)
|
||||
(require 'dbus)
|
||||
|
||||
(defun cmdline-for-pid (pid)
|
||||
"Return the command line arguments passed to PID.
|
||||
PID can be a string or a number."
|
||||
(butlast (string-split
|
||||
(with-temp-buffer
|
||||
(insert-file-contents-literally
|
||||
(format "/proc/%s/cmdline" pid))
|
||||
(buffer-substring-no-properties (point-min)
|
||||
(point-max)))
|
||||
"\0")))
|
||||
(defun current-eww-config-dir ()
|
||||
"Return the configuration directory for a currently running eww process."
|
||||
;; This probably only works on Linux
|
||||
(catch 'found
|
||||
(dolist (subdir (directory-files "/proc"))
|
||||
(when (string-match-p (rx bos (+ num) eos) subdir)
|
||||
(ignore-error permission-denied
|
||||
(let* ((attrs (file-attributes (format "/proc/%s/exe" subdir)))
|
||||
(type (file-attribute-type attrs)))
|
||||
(when (and (stringp type)
|
||||
(string-match-p (rx (or bos "/") "eww") type))
|
||||
(cl-maplist (lambda (tail)
|
||||
(when (equal (car tail) "-c")
|
||||
(throw 'found (cl-second tail))))
|
||||
(cmdline-for-pid subdir)))))))))
|
||||
|
||||
(defun set-eww-fcitx-state (state)
|
||||
"Set the Fcitx state for Eww to STATE."
|
||||
(let ((args (list "update" (format "fcitx5-state=%s" state)))
|
||||
(cfg-dir (current-eww-config-dir)))
|
||||
(when cfg-dir
|
||||
(setq args (nconc (list "-c" cfg-dir) args)))
|
||||
(apply 'call-process "eww" nil 0 nil args)))
|
||||
|
||||
(defun update-waybar ()
|
||||
(call-process "pkill" nil 0 nil "-RTMIN+1" "waybar"))
|
||||
|
||||
(cl-defun has-focused-window-p (&optional (server "server"))
|
||||
"Return non-nil if SERVER has at least one focused window.
|
||||
SERVER defaults to \"server\"."
|
||||
(server-eval-at
|
||||
server '(cl-some 'frame-focus-state (frame-list))))
|
||||
|
||||
(if (has-focused-window-p)
|
||||
(server-eval-at "server" '(my/global-toggle-mozc))
|
||||
(dbus-call-method :session "org.fcitx.Fcitx5" "/controller"
|
||||
"org.fcitx.Fcitx.Controller1" "Toggle")
|
||||
(let ((state (dbus-call-method :session "org.fcitx.Fcitx5" "/controller"
|
||||
"org.fcitx.Fcitx.Controller1" "State")))
|
||||
(set-eww-fcitx-state state)
|
||||
(update-waybar)))
|
||||
|
||||
;; Local Variables:
|
||||
;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
|
||||
;; End:
|
||||
11
status-bar/sb-mu4e-messages
Executable file
11
status-bar/sb-mu4e-messages
Executable file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
let greather_than_zero=0
|
||||
if [[ "${1}" == '-g' ]]; then
|
||||
greather_than_zero=1
|
||||
fi
|
||||
|
||||
lines=(${(f)"$(mu find '(maildir:/protonmail/Inbox or maildir:/ucsc-gmail/Inbox) AND flag:unread' 2>/dev/null)"})
|
||||
if [[ ${#lines} > 0 ]] || ! (( greather_than_zero )); then
|
||||
printf '%d' "${#lines}"
|
||||
fi
|
||||
22
status-bar/sb-network
Executable file
22
status-bar/sb-network
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
let bluetooth=1
|
||||
if [[ "${1}" == '--no-bluetooth' ]] || [[ "${1}" == '-n' ]]; then
|
||||
bluetooth=0
|
||||
fi
|
||||
|
||||
if [[ "$(uname)" = 'Linux' ]]; then
|
||||
local active_networks="$(nmcli --fields type c s --active)"
|
||||
local output=''
|
||||
[[ "${active_networks}" = *'wifi'* ]] && output="${output} "
|
||||
[[ "${active_networks}" = *'ethernet'* ]] && output="${output}"
|
||||
[[ "${active_networks}" = *'wireguard'* ]] && output="${output} "
|
||||
(( ${#output} == 0 )) && output=''
|
||||
if (( bluetooth )); then
|
||||
bluetoothctl show | grep 'Powered: yes' >/dev/null && output="${output} "
|
||||
fi
|
||||
printf '%s\n' "${output}"
|
||||
else
|
||||
echo "${0}: error: unknown os: \"$(uname)\"" >&2
|
||||
exit 1
|
||||
fi
|
||||
28
status-bar/sb-pulse-listener
Executable file
28
status-bar/sb-pulse-listener
Executable file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
function print-volume {
|
||||
let volume="$(pamixer --get-volume)"
|
||||
local icon
|
||||
if [[ "$(pamixer --get-mute)" = "true" ]]; then
|
||||
icon=''
|
||||
elif (( ${volume} >= 50 )); then
|
||||
icon=''
|
||||
elif ((${volume} > 0)); then
|
||||
icon=''
|
||||
elif ((${volume} == 0)); then
|
||||
icon=''
|
||||
else
|
||||
icon='?'
|
||||
fi
|
||||
printf '%s%3d%%\n' "${icon}" "${volume}"
|
||||
}
|
||||
|
||||
print-volume
|
||||
pactl subscribe | \
|
||||
while read line; do
|
||||
case "${line}" in
|
||||
"Event 'change' on sink"*)
|
||||
print-volume
|
||||
;;
|
||||
esac
|
||||
done
|
||||
18
status-bar/sb-toggle-systray
Executable file
18
status-bar/sb-toggle-systray
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
local config_flags=()
|
||||
if ((${#} >= 1)); then
|
||||
config_flags+=("-c" "${1}")
|
||||
fi
|
||||
|
||||
local value="$(eww ${config_flags} get show-systray)"
|
||||
case "${value}" in
|
||||
'false')
|
||||
value='true'
|
||||
;;
|
||||
*)
|
||||
value='false'
|
||||
;;
|
||||
esac
|
||||
|
||||
eww ${config_flags} update show-systray="${value}"
|
||||
Reference in New Issue
Block a user