From 6e2c3d8d2b39a53df8b41f06c3bb9ff3d5cb9538 Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 14 Feb 2021 01:53:43 +0000 Subject: config: fix for transparency handling in sway --- init.org | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/init.org b/init.org index 722b975..7153422 100644 --- a/init.org +++ b/init.org @@ -294,32 +294,40 @@ * Fonts and colour themes *** Transparency #+begin_src emacs-lisp - (defvar jao-frames-default-alpha (if (eq window-system 'pgtk) 96 90)) + (defvar jao-frames-default-alpha (if (eq window-system 'pgtk) 100 90)) + (defvar jao-transparent-p t) - (defun jao-sway-set-transparency () + (defun jao-sway-set-transparency (level) (when jao-sway-enabled-p - (let ((alpha (/ (or (cadr (frame-parameter nil 'alpha)) 100) 100.0))) + (let ((alpha (/ level 100.0))) (jao-swaymsg (format "[app_id=emacs] opacity %s" alpha))))) (defun jao-toggle-transparency (&optional all) (interactive "P") - (if all - (let* ((trans (/= jao-frames-default-alpha 100)) - (new-alpha (if trans 100 jao-frames-default-alpha))) - (modify-all-frames-parameters `((alpha . (,new-alpha ,new-alpha))))) - (if (/= (or (cadr (frame-parameter nil 'alpha)) 100) 100) - (set-frame-parameter nil 'alpha '(100 100)) - (set-frame-parameter nil 'alpha (list jao-frames-default-alpha - jao-frames-default-alpha)))) - (jao-sway-set-transparency)) + (setq jao-transparent-p (not jao-transparent-p)) + (cond (jao-sway-enabled-p + (jao-sway-set-transparency (if jao-transparent-p 90 100))) + (all (let* ((trans (/= jao-frames-default-alpha 100)) + (new-alpha (if trans 100 jao-frames-default-alpha)) + (a `((alpha . (,new-alpha ,new-alpha))))) + (modify-all-frames-parameters a))) + ((/= (or (cadr (frame-parameter nil 'alpha)) 100) 100) + (set-frame-parameter nil 'alpha '(100 100))) + (t (set-frame-parameter nil 'alpha `(,jao-frames-default-alpha + ,jao-frames-default-alpha))))) (defun jao-transparent-p () - (/= (or (cadr (frame-parameter nil 'alpha)) 100) 100)) + (if jao-sway-enabled-p + jao-transparent-p + (/= (or (cadr (frame-parameter nil 'alpha)) 100) 100))) - (defun jao-set-transparency (&optional level) + (defun jao-set-transparency (level) (interactive "nOpacity (0-100): ") - (set-frame-parameter nil 'alpha (list level level)) - (jao-sway-set-transparency)) + (let ((level (or level jao-frames-default-alpha))) + (setq jao-transparent-p (< level 100)) + (if jao-sway-enabled-p + (jao-sway-set-transparency level) + (set-frame-parameter nil 'alpha (list level level))))) #+end_src *** Fonts ***** Unicode fonts -- cgit v1.2.3