0

I've used the toggle-transparency function from https://www.emacswiki.org/emacs/TransparentEmacs

 (eval-when-compile (require 'cl))
 (defun toggle-transparency ()
   (interactive)
   (if (/=
        (cadr (frame-parameter nil 'alpha))
        100)
       (set-frame-parameter nil 'alpha '(100 100))
     (set-frame-parameter nil 'alpha '(85 50))))
 (global-set-key (kbd "C-c t") 'toggle-transparency)

but although this makes the transparency less, it does not completely remove transparency for me (for some reason). I'm on Ubuntu 14.04.

2 Answers 2

1

It turns out while I was trying different ways to set transparency, one being CompizConfig which is a Ubuntu program, I had set a rule that emacs would be 96 transparent (4% transparency) so the max emacs could go was that high. After removing the rule I was able to toggle transparency completely.

1

I do not know whether the following does resolve your problem. Your code has some flaws. Maybe, these cause the dysfunction.

The last sentence of the following section of the frame parameter documentation says that the associated value of alpha can also be a number or nil (when the window manager should handle transparency).

‘alpha’ This parameter specifies the opacity of the frame, on graphical displays that support variable opacity. It should be an integer between 0 and 100, where 0 means completely transparent and 100 means completely opaque. It can also have a ‘nil’ value, which tells Emacs not to set the frame opacity (leaving it to the window manager). ...

Your code will error-out in those cases since cadr expects a list and \= expects numbers as arguments. It handles only the case of the following subsequent section in the doc:

The alpha frame parameter can also be a cons cell(‘active’ . ‘inactive’), where ‘active’ is the opacity of the frame when it is selected, and ‘inactive’ is the opacity when it is not selected.

There follows a modified function toggle-transparency that regards the doc.

(defun toggle-transparency ()
  (interactive)
  (let ((alpha (frame-parameter nil 'alpha)))
    (if (eq
     (if (numberp alpha)
         alpha
       (cdr alpha)) ; may also be nil
     100)
    (set-frame-parameter nil 'alpha '(85 . 50))
      (set-frame-parameter nil 'alpha '(100 . 100)))))
3
  • 1
    That may be a flaw but the problem was from an outside Ubuntu program when I was trying different ways of making Emacs transparent, I forgot to remove a transparency rule and this was limiting Emac's max transparency. Removing the rule from the Ubuntu program (CompizConfig) fixed it
    – irregular
    May 31, 2016 at 15:13
  • Shouldn't the parameters be (85 . 50) and (100 . 100), and should be checked with (cdr alpha) instead of cadr? Though it seems both forms work...
    – npostavs
    May 31, 2016 at 15:31
  • @npostavs Yes, you are right. The info-manual says so. In my info buffer the manual was badly formatted when I read it. The dot between active and inactive was at a line end. Therefore I missed it and went mit the OP. I correct it now. Thanks for the notification.
    – Tobias
    May 31, 2016 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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