0

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?

-1

Forget about changing the lower limit for making any frame transparent, and forget about trying to force redisplay.

All you want to do, apparently, is to toggle the selected frame between a minimum transparency value and a maximum one. And apparently you want to be able to change those values easily anytime.

(defvar my-max-transparency 100 "...")
(defvar my-min-transparency 97 "...")

(defun toggle-transparency ()
  (interactive)
  (set-frame-parameter nil 'alpha
                       (let ((now  (frame-parameter nil 'alpha)))
                         (if (and now  (< now my-max-transparency))
                             my-max-transparency
                           my-min-transparency))))

Use M-: (setq my-min-transparency 42) or whatever.


(defcustom my-max-transparency 100 "..." :type 'integer)
(defcustom my-min-transparency 97  "..." :type 'integer)

Then use M-x customize-option my-min-transparency.

  • That's not what I want to do. I want to toggle transparency between 97 and 100. More precisely, I want to be able to change that 97 setting at will, and still have my toggle function work as expected, toggling between the current value and 100. Did you read the documentation snippet I included? – ivan Aug 13 '16 at 22:14
  • @ivan so put 97 where Drew put 20, problem solved? – npostavs Aug 13 '16 at 23:12
  • @npostavs I guess I'm not being clear about what I mean. I'd like to be able to change the alpha parameter to whatever I want on the fly (interactively), and have the toggle respect the new value. – ivan Aug 14 '16 at 1:15
  • Then define two limits as global variables, and use those in the toggle function. You can use defvar or, if you want to be able to use Customize, defcustom. – Drew Aug 14 '16 at 1:16
  • Does this not satisfy your request? Please let us know, if we're still misunderstanding your question. – Drew Aug 14 '16 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.