2009-02-18

transparent emacs

It may not be so useful, but emacs23 allows you to manipulate the transparency of your emacs frames (windows). If you use Windows or X with a compositing window manager on X, you can make your windows transparent. Examples of compositing window managers are Compiz/Beryl and even the good-old Metacity (gconftool-2 -s '/apps/metacity/general/compositing_manager' --type bool true).

The following code for your .emacs makes it easy to set transparency from within emacs:

(defun djcb-opacity-modify (&optional dec)
  "modify the transparency of the emacs frame; if DEC is t,
    decrease the transparency, otherwise increase it in 10%-steps"
  (let* ((alpha-or-nil (frame-parameter nil 'alpha)) ; nil before setting
          (oldalpha (if alpha-or-nil alpha-or-nil 100))
          (newalpha (if dec (- oldalpha 10) (+ oldalpha 10))))
    (when (and (>= newalpha frame-alpha-lower-limit) (<= newalpha 100))
      (modify-frame-parameters nil (list (cons 'alpha newalpha))))))

 ;; C-8 will increase opacity (== decrease transparency)
 ;; C-9 will decrease opacity (== increase transparency
 ;; C-0 will returns the state to normal
(global-set-key (kbd "C-8") '(lambda()(interactive)(djcb-opacity-modify)))
(global-set-key (kbd "C-9") '(lambda()(interactive)(djcb-opacity-modify t)))
(global-set-key (kbd "C-0") '(lambda()(interactive)
                               (modify-frame-parameters nil `((alpha . 100)))))
Now, you can make make emacs more transparent (less opaque) by pressing C-9, while C-8 has the opposite effect. C-0 brings us back to normality.

Admittedly, window transparency is a classical solution-looking-for-a-problem. But let that not stop us from using it -- now we can watch full-screen movies while still using emacs. That, my friends, is progress.

20 comments:

Cano said...

Very cute!

Zerd said...

Where did you get that wallpaper?

djcb said...

@Zerd: interfacelift.com

Unknown said...

Your desktop theme is cool .

Gnome ? how you configure it

Anonymous said...

Is there any way to do this without using a compositing desktop? I currently have a transparent gnome-terminal on my non-compositing xmonad setup. It would be cool if I could do the same with emacs

djcb said...

@Jing: nothing special; gnome with 'MurrinaMyDark' (gtk+) and 'New Wave Dark Menus' (metacity) -- get them from gnome-look.org

@Anonymous: I guess you could try 'xcompmgr'.

wickedtribe said...

Sir, I submit to you that watching a full screen movie while working in emacs *is* a problem that GNUemacs23 has solved!

Anonymous said...

Try this: to speedbar-frame-parameters add the cons cell '(100 . 50)

Then speedbar will be 50% opaque when not active, and fully opaque when you switch to speedbar.

I'm using it right now.

Anonymous said...

Thanks. Works under Xfce. How to make it work for KDE4? Has anybody tried it yet?

Fidel said...

Awesome!!

Anonymous said...

Any idea on how to use a .jpg as a background instead of my desktop. My desktop is a cluttered mess and it stresses me out to see it in Emacs.

However, I'd like to see a nice ocean view to calm my nerves during defect fixes.

Hints anyone?

djcb said...

@Anonymous: I don't think that's possible currently -- however, why don't you just move all the Desktop clutter in a folder called 'DesktopClutter', and get a nice relaxing background image from e.g. interfacelift.com (when it's back)?

Jagadeesh said...

Thank you for sharing such nice feature of emacs.

geo_libres said...

Gracias, es el complemento perfecto para la ediciĆ³n de video con
gneve-mode

Unknown said...

is there any way to have a transparent background color without having the entire window transparent?

Gabriel Saldana said...

Do u know of a way to make transparency work on KDE4?

djcb said...

@Gabriel Saldana: it seems not to work with KDE4 (or with Gnome-Shell, for that matter). File a bug, I'd say.

Anonymous said...

Very cool. Works perfectly on Windows 7. Thanks!

Unknown said...

What do I have to do to make it work under compiz?

Anonymous said...

Thank you, very cool.
Is there a way to keep the text opaque?

Cheers,
Timo