Toggle fullscreen in Emacs

Today I improved the function I was using to toggle full screen in GNU Emacs.

(defun toggle-fullscreen (&optional f)
  (let ((current-value (frame-parameter nil 'fullscreen)))
       (set-frame-parameter nil 'fullscreen
                            (if (equal 'fullboth current-value)
                                (if (boundp 'old-fullscreen) old-fullscreen nil)
                                (progn (setq old-fullscreen current-value)

(global-set-key [f11] 'toggle-fullscreen)

The previous function would always restore the frame to "normal" state, even if Emacs was previously maximized. This one makes it behave more like, say, Epiphany or Totem.

Apparently using GNOME Keyboard Shortcuts to set this to F11 globally would override custom behaviour from some programs. I've not found any examples of this, though. This would be easily extensible to disable the Emacs toolbar when fullscreen, for instance.

Tim Retout

A solution architect

By Tim Retout, 2010-07-09