From ee1321e857a7282a7dabd5bea759fa02567d8a52 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Tue, 4 Feb 2025 21:02:12 -0800 Subject: [PATCH] Some changes --- eww/eww-fcitx5-toggle | 63 +++++++++++++++++++++++++++++--- eww/eww-mu4e-messages | 21 ++--------- sound-control.sh | 6 ++- swayidle-lock-screen | 4 +- system-menu/confirm-logout.sh | 11 +++++- system-menu/system-sleep-menu.sh | 6 +++ 6 files changed, 83 insertions(+), 28 deletions(-) diff --git a/eww/eww-fcitx5-toggle b/eww/eww-fcitx5-toggle index b31dc2b..1d1bc5d 100755 --- a/eww/eww-fcitx5-toggle +++ b/eww/eww-fcitx5-toggle @@ -1,6 +1,57 @@ -#!/bin/sh -if [ "${#}" -gt 0 ]; then - config_flags="-c ${1}" -fi -fcitx5-remote -t -eww ${config_flags} update fcitx5-state="$(fcitx5-remote)" +#!/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))) + +(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))) + +;; Local Variables: +;; flycheck-disabled-checkers: (emacs-lisp-checkdoc) +;; End: diff --git a/eww/eww-mu4e-messages b/eww/eww-mu4e-messages index 2fb8fc6..f7ad105 100755 --- a/eww/eww-mu4e-messages +++ b/eww/eww-mu4e-messages @@ -1,17 +1,4 @@ -#!/usr/bin/env -S emacs -x -;;; -*- mode: emacs-lisp; lexical-binding: t -*- -(require 'server) -(princ - (condition-case _ - (if-let ((modeline-string (server-eval-at "server" '(mu4e--modeline-string))) - ((string-match "\\([0-9]+\\)\\((\\+[0-9]+)\\)?/[0-9]+ $" modeline-string)) - (matched-string (match-string 1 modeline-string))) - (progn - (set-text-properties 0 (length matched-string) - nil - matched-string) - matched-string) - "0") - (error - "0"))) -(terpri) +#!/usr/bin/env zsh + +lines="${(f)$(mu find 'maildir:/protonmail/Inbox AND flag:unread' 2>/dev/null)}" +printf '%d' "${#lines}" diff --git a/sound-control.sh b/sound-control.sh index 593e963..27fe66c 100755 --- a/sound-control.sh +++ b/sound-control.sh @@ -24,10 +24,12 @@ function notify_vol { local icon if [[ "$(pamixer --get-mute)" == 'true' ]]; then icon='󰸈' - elif (( ${vol} > 50 )); then + elif (( ${vol} >= 50 )); then icon='󰕾' - elif (( ${vol} >= 0 )); then + elif ((${vol} > 0)); then icon='󰖀' + elif ((${vol} == 0)); then + icon='󰕿' else icon='?' fi diff --git a/swayidle-lock-screen b/swayidle-lock-screen index 1702ec3..bbd2408 100755 --- a/swayidle-lock-screen +++ b/swayidle-lock-screen @@ -14,11 +14,11 @@ function has-rootful-xwayland-p { function run { # ensure multiple instances do not run - mkdir -p "$(dirname "${LOCKFILE}")" + mkdir -p "${LOCKFILE:h}" exec 4<>"${LOCKFILE}" flock -n 4 || exit 0 dunstctl set-paused true - if has-rootful-xwayland-p; then + if [[ "${XDG_CURRENT_DESKTOP}" == 'river' ]] && has-rootful-xwayland-p; then swaylock ${empty_flag} --color '#000000' else swayidle -w -C /dev/null \ diff --git a/system-menu/confirm-logout.sh b/system-menu/confirm-logout.sh index 06d4c4e..5ab9cfd 100755 --- a/system-menu/confirm-logout.sh +++ b/system-menu/confirm-logout.sh @@ -2,4 +2,13 @@ local resp="$(printf 'No\nYes\n' | fuzzel --dmenu --prompt 'Really Logout> ')" -[[ "${resp}" == 'Yes' ]] && riverctl exit +if [[ "${resp}" == 'Yes' ]]; then + case "${XDG_CURRENT_DESKTOP}" in + Hyprland) + hyprctl dispatch exit + ;; + river) + riverctl exit + ;; + esac +fi diff --git a/system-menu/system-sleep-menu.sh b/system-menu/system-sleep-menu.sh index 44d78d7..da652c2 100755 --- a/system-menu/system-sleep-menu.sh +++ b/system-menu/system-sleep-menu.sh @@ -36,3 +36,9 @@ case "${choice}" in fi ;; esac + +if [[ "${XDG_CURRENT_DESKTOP}" == 'river' ]]; then + eww -c "${HOME}/.config/river/config/" update swayidle="$(( ! ${choice} ))" +elif [[ "${XDG_CURRENT_DESKTOP}" == 'Hyprland' ]]; then + pkill -SIGRTMIN+1 waybar +fi