X-Git-Url: https://git.shemshak.org/~bandali/configs/blobdiff_plain/188c64b591f6341844f4bc6906e8cc9b23ad3b14..20b58f4d603c55b1aba42cc375a97b8708f725ba:/.emacs.d/init.el diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 8d05845..94f1ccb 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -193,7 +193,7 @@ (with-eval-after-load 'time (setq display-time-default-load-average nil - display-time-format " %a %b %-e %-l:%M%P" + display-time-format " %a %Y-%m-%d %-l:%M%P" display-time-mail-icon '(image :type xpm :file "gnus/gnus-pointer.xpm" :ascent center) @@ -207,16 +207,83 @@ (run-with-idle-timer 0.1 nil #'require 'battery) (with-eval-after-load 'battery - (setq battery-mode-line-format " %p%% %t") + (setq battery-mode-line-format " [%p%% %t]") (display-battery-mode)) +(progn ; display system volume in mode-line + (defun b/get-volume-level (&optional mic) + "Returns the current system sound volume. +If MIC is non-nil, it returns the microphone volume instead." + (string-to-number + (string-trim + (shell-command-to-string + (mapconcat + #'identity + `("pamixer" ,(when mic "--default-source") "--get-volume") + " "))))) + + (defun b/set-volume-level (level &optional mic) + "Set the system sound volume to LEVEL. +If MIC is non-nil, set the volume level for the microphone +instead." + (let ((v (if mic 'b/volume-level-mic 'b/volume-level))) + (eval `(setq ,v ,level)))) + + (defun b/get-volume-mute (&optional mic) + "Returns t if system sound is currently muted. +If MIC is non-nil, it instead returns t if the microphone is +muted." + (string= + "true" + (string-trim + (shell-command-to-string + (mapconcat + #'identity + `("pamixer" ,(when mic "--default-source") "--get-mute") + " "))))) + + (defun b/set-volume-mute (mute &optional mic) + "Set the system sound mutedness to MUTE. +If MIC is non-nil, set the mutedness for the microphone instead." + (let ((v (if mic 'b/volume-mute-mic 'b/volume-mute))) + (eval `(setq ,v ,mute)))) + + (defvar b/volume-level (b/get-volume-level)) + (defvar b/volume-mute (b/get-volume-mute)) + (defvar b/volume-level-mic (b/get-volume-level 'mic)) + (defvar b/volume-mute-mic (b/get-volume-mute 'mic)) + + (setq-default + mode-line-format + (append + mode-line-format + '((:eval + (format + " [%s%%%%%s %s%%%%%s]" + (number-to-string b/volume-level) + (if b/volume-mute "-" "+") + (number-to-string b/volume-level-mic) + (if b/volume-mute-mic "-" "+"))))))) + ;; (with-eval-after-load 'fringe ;; ;; smaller fringe ;; (fringe-mode '(3 . 1))) (run-with-idle-timer 0.5 nil #'require 'winner) (with-eval-after-load 'winner - (winner-mode 1)) + (winner-mode 1) + (when (featurep 'exwm) + ;; prevent a bad interaction between EXWM and winner-mode, where + ;; sometimes closing a window (like closing a terminal after + ;; entering a GPG password via pinentry-gnome3's floating window) + ;; results in a dead frame somewhere and effectively freezes EXWM. + (advice-add + 'winner-insert-if-new + :around + (lambda (orig-fun &rest args) + ;; only add the frame if it's live + (when (frame-live-p (car args)) + (apply orig-fun args)))))) (run-with-idle-timer 0.5 nil #'require 'windmove) (with-eval-after-load 'windmove @@ -272,8 +339,7 @@ (with-eval-after-load 'ediff (setq ediff-window-setup-function 'ediff-setup-windows-plain - ediff-split-window-function 'split-window-horizontally) - (add-hook 'ediff-after-quit-hook-internal #'winner-undo)) + ediff-split-window-function 'split-window-horizontally)) (with-eval-after-load 'face-remap (setq @@ -418,12 +484,19 @@ Make N (default: 1) copies of the current line or region." (dotimes (_ (abs n1)) (insert text)))))) -(defun b/invert-default-face () - "Invert the `default' face (swap its background and foreground). -Effectively a very simple light/dark theme toggle switch." - (interactive) - (invert-face 'default (selected-frame)) - (invert-face 'mode-line (selected-frame))) +(defun b/invert-default-face (arg) + "Invert the `default' and `mode-line' faces for the current frame. +Swap the background and foreground for the two `default' and +`mode-line' faces, effectively acting like a simple light/dark +theme toggle. If prefix argument ARG is given, invert the faces +for all frames." + (interactive "P") + (let ((frame (unless arg + (selected-frame)))) + (invert-face 'default frame) + (invert-face 'mode-line frame)) + (when (fboundp #'exwm-systemtray--refresh-background-color) + (exwm-systemtray--refresh-background-color 'remap))) (defun b/export-frame () (interactive) @@ -484,8 +557,14 @@ Effectively a very simple light/dark theme toggle switch." (expand-file-name (convert-standard-filename "lisp") user-emacs-directory)) -(when (member (system-name) '("chaman")) - (require 'bandali-exwm)) +(when + (and + (display-graphic-p) + ;; we're not running in another WM/DE + (not (getenv "XDG_CURRENT_DESKTOP")) + (member (system-name) '("chaman" "langa"))) + (require 'bandali-exwm) + (global-set-key (kbd "C-x b") #'exwm-workspace-switch-to-buffer)) (require 'bandali-org)