Compare commits

..

4 Commits

4 changed files with 56 additions and 24 deletions

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env -S emacs -Q --script
;;; -*- lexical-binding: t -*-
(require 'cl-lib)
(require 'server)
(defun append-to-path (value)
"Split VALUE and append to PATH."
(let ((to-add (split-string value ":" t nil)))
(server-eval-at "server"
`(dolist (file ',to-add)
(add-to-list 'exec-path file)))))
(dolist (var argv)
(let ((sep (cl-position ?= var :test #'eql)))
(cond
((string-prefix-p "-" var)
;; unset
(when (equal var "-PATH")
(message "Refusing to unset PATH")
(kill-emacs 1))
(server-eval-at "server"
`(setenv ,(substring var 1) nil)))
(sep
(let ((name (substring var 0 sep))
(value (substring var (1+ sep))))
(if (equal name "PATH")
(append-to-path value)
;; append to PATH, not set
;; set to passed value
(server-eval-at "server"
`(setenv ,name ,value)))))
(t
(if (equal var "PATH")
;; copy form and append to path
(append-to-path (getenv var))
;; copy from our evnironment
(server-eval-at "server"
`(setenv ,var ,(getenv var))))))))
;; Local Variables:
;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
;; End:

View File

@@ -1,12 +0,0 @@
#!/usr/bin/env zsh
setopt rcquotes
printf '%s' "${WAYLAND_DISPLAY}" |
/usr/bin/emacs --batch --insert=/dev/fd/0 \
--eval \
'(let ((wayland-display (buffer-string)))
(require ''server)
(server-eval-at
"server"
`(setenv "WAYLAND_DISPLAY" ,wayland-display)))'

View File

@@ -14,12 +14,21 @@ function has-rootful-xwayland-p {
return 1 return 1
} }
function safeeyes-running-p {
[[ "$(safeeyes --status)" = Next* ]]
}
function run { function run {
# ensure multiple instances do not run # ensure multiple instances do not run
mkdir -p "${LOCKFILE:h}" mkdir -p "${LOCKFILE:h}"
exec 4<>"${LOCKFILE}" exec 4<>"${LOCKFILE}"
flock -n 4 || exit 0 flock -n 4 || exit 0
dunstctl set-paused true dunstctl set-paused true
let need_restore_safeeyes=0
if safeeyes-running-p; then
safeeyes --disable
need_restore_safeeyes=1
fi
if [[ "${XDG_CURRENT_DESKTOP}" == 'river' ]] && has-rootful-xwayland-p; then if [[ "${XDG_CURRENT_DESKTOP}" == 'river' ]] && has-rootful-xwayland-p; then
swaylock ${empty_flag} --color '#000000' swaylock ${empty_flag} --color '#000000'
else else
@@ -35,17 +44,16 @@ function run {
swayidle -w -C /dev/null \ swayidle -w -C /dev/null \
timeout 15 "${(q)ENABLE_DISPLAYS} -d ${ignored_args}" \ timeout 15 "${(q)ENABLE_DISPLAYS} -d ${ignored_args}" \
resume "${(q)ENABLE_DISPLAYS} {$ignored_args}" & resume "${(q)ENABLE_DISPLAYS} {$ignored_args}" &
# after-resume "${(q)RESET_SAFEEYES}" \
swayidle_pid="${!}" swayidle_pid="${!}"
else else
swayidle -w -C /dev/null \ swayidle -w -C /dev/null \
timeout 15 "systemctl sleep" & timeout 15 "systemctl sleep" &
# after-resume "${(q)RESET_SAFEEYES}" \
swayidle_pid="${!}" swayidle_pid="${!}"
fi fi
swaylock ${empty_flag} ${img_flags} swaylock ${empty_flag} ${img_flags}
kill "${swayidle_pid}" kill "${swayidle_pid}"
fi fi
(( need_restore_safeeyes )) && safeeyes --enable
dunstctl set-paused false dunstctl set-paused false
fix_eww fix_eww
flock -u 4 flock -u 4

View File

@@ -11,10 +11,7 @@ DUNSTIFY_EXEC_NAME = shutil.which("dunstify")
open_notifications = {} open_notifications = {}
def parse_event_type_and_id(stream): def parse_event_type_and_id(line):
line = stream.readline()
if not line:
return None, True
if not line.startswith("[device] "): if not line.startswith("[device] "):
return None, False return None, False
event_type = re.findall("(?<=\\[device\\] )[a-zA-Z]+", line) event_type = re.findall("(?<=\\[device\\] )[a-zA-Z]+", line)
@@ -107,12 +104,8 @@ with Popen(
first_line = ( first_line = (
usbguard_proc.stdout.readline() usbguard_proc.stdout.readline()
) # get rid of initial connection message ) # get rid of initial connection message
if not first_line: for line in usbguard_proc.stdout:
sys.exit() event_type_result = parse_event_type_and_id(line)
while True:
event_type_result, eof = parse_event_type_and_id(usbguard_proc.stdout)
if eof:
sys.exit()
if event_type_result is None: if event_type_result is None:
continue continue
event_type, dev_id = event_type_result event_type, dev_id = event_type_result