running emacs in full-screen mode

Sometimes it's nice to run emacs in full-screen mode; for example if you don't want to be distracted by your pretty desktop wallpaper etc. When we're using the X-Window system, we can ask the wmctrl-program to make our window full-screen by adding the following to .emacs:
(defun djcb-full-screen-toggle ()
  "toggle full-screen mode"
  (shell-command "wmctrl -r :ACTIVE: -btoggle,fullscreen"))
This requires the wmctrl program, for which there is (hopefully) a package in your distribution.

We can make a keybinding for this to, say, F11, which is the same one that e.g. FireFox use:

(global-set-key (kbd "<f11>")  'djcb-full-screen-toggle)

Note that instead of shell-command we could use the djcb-shell-command-maybe function instead, and get a warning if wmctrl is not installed.


Joe Casadonte said...

For Win32 I have the following (Note: it was not mine originally):

;;;; ------------------------------------------------------------------------
;;;; --- Frame max toggle - From: "rgb" / gnu.emacs.help / 18 Mar 2005 16:30:32 -0800
;;;; --- See also: http://www.emacswiki.org/cgi-bin/wiki/WThirtyTwoSendSysCommand
;;;; ------------------------------------------------------------------------
(make-variable-frame-local 'my-frame-state)

(defun my-frame-maximize ()
"Maximize Emacs window in win32"

(modify-frame-parameters nil '((my-frame-state . t)))
(w32-send-sys-command ?\xf030))

(defun my-frame-restore ()
"Restore Emacs window in win32"

(modify-frame-parameters nil '((my-frame-state . nil)))
(w32-send-sys-command ?\xF120))

(defun my-frame-toggle ()
"Maximize/Restore Emacs frame based on `my-frame-state'"
(if my-frame-state

Bruce Durling said...

I like this a lot. I've added it to my .emacs. Thanks!

djcb said...

@Bruce: with a sufficiently recent emacs, a method without any external programs is:
(defun djcb-fullscreen-toggle ()
(set-frame-parameter nil 'fullscreen
(if (frame-parameter nil 'fullscreen) nil 'fullboth)))
This should work on Mac/Win/C64 as well.

Bruce Durling said...

That works really well on my latest emacs from the git mirror of cvs on Ubuntu 9.04. Thanks for the tip.

Anonymous said...

Could you make a WriteRoom like minor-mode.
That is full screen plus a potential enlarged font.
So basically it would be a minor mode that
1) maximized the frame
2) variable-pitch-mode or buffer-face-mode
3) Increased margins and enlarged font.

Would that be possible?

djcb said...

@Anonymous: sure, that shouldn't be too hard; see the information in http://www.emacswiki.org/emacs/WriteRoom
and check the docs for 'define-minor-mode'

Also http://www.emacswiki.org/emacs/TheaterStyle might be interesting.

marc said...


But djcb-fullscreen-toggle do not exactly the same job as my-frame-maximize.