I configured emacs to be slightly transparent in my init.el
(set-frame-parameter (selected-frame) 'alpha '(97 . 85))
(add-to-list 'default-frame-alist '(alpha . (97 . 85)))
I wanted to be able to toggle transparency on/off, and I saw this in the documentation for Font and Color Parameters:
To prevent the frame from disappearing completely from view, the variable
frame-alpha-lower-limit
defines a lower opacity limit. If the value of the frame parameter is less than the value of this variable, Emacs uses the latter. By default,frame-alpha-lower-limit
is 20.
Flipping frame-alpha-lower-limit
between 100 and its default 20 seemed like a good way to implement the toggle without having to hard-code my alpha settings into it or record any previous values.
(defun ivan/toggle-transparency ()
(interactive)
(setq frame-alpha-lower-limit
(if (eql frame-alpha-lower-limit 100) 20 100)))
But changing the lower limit doesn't trigger any re-evaluation of the relationship between the alpha parameter and its lower limit. I tried (redraw-frame)
and (sit-for 0)
, but the only thing that worked was using set-frame-parameter
to set the alpha to it's current setting.
(defun ivan/toggle-transparency ()
(interactive)
(setq frame-alpha-lower-limit
(if (eql frame-alpha-lower-limit 100) 20 100))
(set-frame-parameter (selected-frame)
'alpha
(frame-parameter (selected-frame) 'alpha)))
Is there any other way to do this?