3

I want to make the tooltip background somewhat transparent, say, change it alpha value to 0.5.

I find these code in tooltip.el.gz

(defface tooltip
  '((((class color))
     :background "lightyellow"
     :foreground "black"
     :inherit variable-pitch)
    (t
     :inherit variable-pitch))
  "Face for tooltips."
  :group 'tooltip
  :group 'basic-faces)

There is a :background property, so my question is:

  1. How to change this value in my init.el so that I do not change the origin file.
  2. How to make it transparent?

Thanks!

rpluim
  • 4,605
  • 8
  • 22
cmal
  • 775
  • 3
  • 14
  • the configuration in the local configuration file will override the default. also look in https://www.gnu.org/software/emacs/manual/html_node/elisp/Faces.html#Faces – manandearth Oct 26 '18 at 05:32

2 Answers2

2

You didn't specify which platform you're on, but under X11 you can do something like

(setq x-gtk-use-system-tooltips nil)
(setf (alist-get 'alpha tooltip-frame-parameters) 0.5)

The first line is needed because otherwise emacs will use GTK tooltips, which don't respect the tooltip frame parameters. There does seem to be some support in GTK for changing the alpha of the tooltip frame via a theme.

rpluim
  • 4,605
  • 8
  • 22
1

Customize option tooltip-frame-parameters, specifying an alpha parameter value that is less than 100.

See the Elisp manual, node Font and Color Parameters, for information about parameter alpha. There, you see this:

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).

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.

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.

Some window systems do not support the alpha parameter for child frames (see Child Frames).

Drew
  • 75,699
  • 9
  • 109
  • 225