FullScreen

Starting in fullscreen mode

From the Emacs Linux man page (command line “man emacs”), for maximized frame, and for complete full screen:

-mm, --maximizedMaximize the first frame, like “-fw -fh” (since Emacs 23.2)
-fs, --fullscreenMake the first frame fullscreen

For example:

emacs -mm [files]

On MS Windows, when parameters don’t work, use the following line instead in your .emacs init file to start with maximized frame:

(w32-send-sys-command 61488)

Configuring fullscreen mode

Probably the simplest way to configure fullscreen or maximized mode is to customize initial-frame-alist

(custom-set-variables
 '(initial-frame-alist (quote ((fullscreen . maximized)))))

Maximize/Restore Using Library frame-cmds.el

Library frame-cmds.el provides various commands to maximize and restore frames horizontally, vertically, or both. It applies to any platform and any Emacs version (20+), and it can take into account a standalone minibuffer frame, the MS Windows task bar, and Mac areas that should not be covered.

As is true for other methods mentioned on this page, “maximized” here is not quite the same thing as “full-screen”. Maximizing here means making a frame as big as possible (possibly leaving room for the things mentioned above), but the frame still appears as a frame, with title bar, border, etc.

frame-cmds.el also includes other, related commands, to tile frames across or down your display, for instance. These are the commands relevant to this topic:

At least on my Ubuntu installation, directly calling (toggle-fullscreen) from the .emacs gives weird layout behaviour. It seems that window resizes have to take place after something which is evaluated after the .emacs, so this did the job for me:

(run-with-idle-timer 0.1 nil 'toggle-fullscreen)

Note that an after-init-hook didn’t work for me.

Platform-specific methods

These methods may be useful with older versions of Emacs, or ports where the ‘fullscreen’ frame parameter is not supported.

MS Windows

The simplest way to get near fullscreen editing is to hide the Windows taskbar and maximize the current Emacs frame. You can use the control panel to make the taskbar always hidden (autohide), or call TSTBARSET from the command line with the appropriate flag to toggle the taskbar’s visibility. (TSTBARSET is a utility to manipulate the taskbar from the command line; scroll near the bottom of linked page to download it).

If the menubar on the emacs frame still bothers you, a call to emacs-fullscreen-win32 listed below will get rid of it.

Emacs 24.4

Emacs 24.4 fully supports fullscreen on Windows. Use M-x toggle-frame-fullscreen to toggle it. The window will go fullscreen on the window’s owning screen.

darkroom-mode

If you’re using MS Windows, and want to use “real fullscreen”, i.e, getting rid of the top titlebar and all, see w32-fullscreen at the site for darkroom-mode

Binary patch

Alternatively, a patch is available here that makes the fullscreen frame parameter really fullscreen on Windows.

emacs-fullscreen-win32

Another option is to use emacs-fullscreen-win32 project. It allows you to switch to/from full-screen mode.

Basic settings
(defun toggle-full-screen () (interactive) (shell-command "emacs_fullscreen.exe"))
(global-set-key [f11] 'toggle-full-screen)
Hide Emacs bars forever

If you want to hide menu-bar, tool-bar, and scroll-bar forever, then use this code:

(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
Start in full-screen mode

If you want to start Emacs in full-screen mode then put call to toggle-full-screen function into your .emacs file:

(toggle-full-screen)
Hide bars in full-screen mode and show them in windowed mode

If you want to hide menu-bar, tool-bar, and scroll-bar in full-screen mode and restore them in windowed mode then use this code:

(defun toggle-full-screen ()
  "Toggles full-screen mode for Emacs window on Win32."
  (interactive)
  (shell-command "emacs_fullscreen.exe"))

(defun toggle-bars ()
  "Toggles bars visibility."
  (interactive)
  (menu-bar-mode)
  (tool-bar-mode)
  (scroll-bar-mode))

(defun toggle-full-screen-and-bars ()
  "Toggles full-screen mode and bars."
  (interactive)
  (toggle-bars)
  (toggle-full-screen))

(global-set-key [f11] 'toggle-full-screen-and-bars)
Example of .emacs file

Here is a part of my .emacs file. Emacs will start in full-screen mode. Menu-bar, tool-bar, and scroll-bar are visible in windowed mode (and are invisible in full-screen mode):

;; Hide splash-screen and startup-message
(setq inhibit-splash-screen t)
(setq inhibit-startup-message t)

(defun toggle-full-screen ()
  "Toggles full-screen mode for Emacs window on Win32."
  (interactive)
  (shell-command "emacs_fullscreen.exe"))

(defun toggle-bars ()
  "Toggles bars visibility."
  (interactive)
  (menu-bar-mode)
  (tool-bar-mode)
  (scroll-bar-mode))

(defun toggle-full-screen-and-bars ()
  "Toggles full-screen mode and bars."
  (interactive)
  (toggle-bars)
  (toggle-full-screen))

;; Use F11 to switch between windowed and full-screen modes
(global-set-key [f11] 'toggle-full-screen-and-bars)

;; Switch to full-screen mode during startup
(toggle-full-screen-and-bars)
Topmost window

emacs_fullscreen.exe supports --topmost command line switch. If this switch is present, then Emacs window will be topmost. It will hide task bar and all other windows. The downside is that if you want to switch to other window, you cannot use Alt+Tab directly, you have to turn off the full screen mode first (see 866d015f9a7b changeset).

Another Fullscreen

While trying above solutions I have found some minor annoyances: some solutions are leaving few row of pixels on the bottom of the screen uncovered so I can see backrgound behind and none of them will restore window back to original position.

To fix those annoyances I have hacked my own small version of toggle-fullscreen window. Unfortunately I also had to go with extern binary since Emacs does not have built-in functionality to correctly detect its own frame geometry (at least what I know by now). I am using win32 functions to detect frame size and position and std in/out to communicate back those for restoring after fullscreen mode. It is just simple and crude hack, but it works 😊.

Binary can be downloaded from Github. Source code along with makefile for gcc/mingw are also provided (just compile main.c to emacs_fullscr.exe). Binary should be placed somewhere in the path.

Function toggle-fullscreen is found in toggle-fullscreen.el. Place file somwhere in emacs elisp path and byte-compile it.

In .emacs or elsewhere one can (require ‘toggle-fullscreen).

It can be called interactively by M-x toggle-fullscreen, or bound to a key.

This solution does nothing else but toggles active Emacs frame to fullscreen and back. If you want more it can be built on top of it.

Maximizing window (not real full-screen)

To get a maximized window you can use: (w32-send-sys-command #xf030)

Attention! If you want that emacs starts maximized, you have to put this code into your .emacs file:

(defun jbr-init ()
  "Called from term-setup-hook after the default
terminal setup is
done or directly from startup if term-setup-hook not
used.  The value
0xF030 is the command for maximizing a window."
  (interactive)
  (w32-send-sys-command #xf030)
  (ecb-redraw-layout)
  (calendar)
)
(setq term-setup-hook 'jbr-init)
(setq window-setup-hook 'jbr-init)

True Fullscreen Patch for Emacs 24.1

I admire the unobtrusive UI of Emacs. But the one thing I painfully missed was the ability to truly fullscreen Emacs on Windows. So I took the Emacs 24.1 codebase and crudely patched the window handling code to let it create a window without the title bar for the first frame. I use this patch on Windows XP SP3 and Windows 7.

trueFullscreen.patch

The combination of the font and screen size could leave gaps on the lower and right side of the screen. To correct this, play around with the font size and the internal border width:

%EMACS_DIR%\bin\runemacs.exe --xrm="emacs.verticalScrollBars:off" --xrm="emacs.menuBar:off" --xrm="emacs.toolBar:0" --font "Courier New-13" --fullscreen --internal-border=4

If you need to minimize the frame, you can use something like this:

(defun minimize-frame ()
  (interactive)
  (w32-send-sys-command #xf020))

MikeVeldink

Using a AutoHotKey script in order to remove the gaps left by borderless fullscreen

I dabbled with a AutoHotKey script for getting this to work properly, and this is my solution:

SetTitleMatchMode 1 ; matches only the start of the window name
WinMaximize, emacs@ ; emacs@ refers to the title of the window
WinSet, Style, -0x40000, emacs@ ; removes the thick frame
WinSet, Style, -0x800000, emacs@ ; removes the rest of the border

Put this into a text file, change the extension to .ahk and right click and select compile in order to compile it (you need AutoHotKey installed). The 3rd and 4th line disables thick borders (WS_THICKFRAME) and the border (WS_BORDER) respectively. If done in this order, I get no gaps where the background shines through. In order to do this automatically every time you start emacs, add this to your .emacs

(shell-command "<name of compiled ahk script>")

Where the <> and contents is replaced by the filename (with extension) of the complied ahk script. Make sure the complied script is in your path (search for changing environmental variables in a search engine if you don’t know how to do this). I’m using the GNU distribution of Emacs 24.3, using 2560x1600 resolution with the Terminus font (size 9). I’m running this on Windows 8.1. Note that I have also added

(tool-bar-mode -1)

to my .emacs (which is when the problems started occuring.)

I’ve experimented with other fonts and different font sizes. This seems robust.

X Window

Emacs Frame Properties

The following maps the function 11 key to toggle fullscreen on X11 (Linux, BSD, etc…).

I (Ivan Kanis) have tested it works on Emacs 24.1.

(defun toggle-fullscreen ()
  "Toggle full screen on X11"
  (interactive)
  (when (eq window-system 'x)
    (set-frame-parameter
     nil 'fullscreen
     (when (not (frame-parameter nil 'fullscreen)) 'fullboth))))

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

Send X Messages to the Window Manager

     (defun fullscreen ()
       (interactive)
       (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
	    		 '(2 "_NET_WM_STATE_FULLSCREEN" 0)))

Or to only maximize window:

     (defun fullscreen (&optional f)
       (interactive)
       (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
	    		 '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
       (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
	    		 '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0)))

External program: wmctrl

If you want to bind F11 to toggle full-screen, here is what you need:

    (defun switch-full-screen ()
      (interactive)
      (shell-command "wmctrl -r :ACTIVE: -btoggle,fullscreen"))
    (global-set-key [f11] 'switch-full-screen)

That does the trick, and now you are GNOME HIG compliant 😊

    (defun switch-full-screen ()
      (interactive)
      (shell-command "wmctrl -r :ACTIVE: -btoggle,maximized_vert,maximized_horz"))
    (defun switch-full-screen ()
      (interactive)
      (shell-command (concat "wmctrl -i -r " (frame-parameter nil 'outer-window-id) " -btoggle,maximized_vert,maximized_horz"))

External program: devilspie

http://patrick.wagstrom.net/weblog/linux/full-screen-emacs.xml

    ;;
    ;; ~/.devilspie/emacs.ds
    ;;
    (if (or (contains (window_class) "emacs") (contains (window_class) "Emacs"))
        (undecorate fullscreen))

Gnome Keyboard Shortcuts

If you use GNOME you can assign a Keyboard Shortcut to toggle Full Screen or not. Just go to

System ⇒ Preferences ⇒ Keyboard Shortcuts

And bind the option “Toggle fullscreen mode” to a key which can be used when using Emacs to toggle full screen or not.

The disadvantage of this is that if you bind F11 so that emacs matches other programs, then the window manager handles the resize/de-chroming and the application does not get a chance to modify it’s appearance. For example, Mozilla Firefox will not set its toolbars to auto-hide.

Mac OS X

Emacs 24.4

Use ‘ns-use-native-fullscreen’ to get “native” fullscreen on OS X 10.7.

Both M-x toggle-frame-fullscreen or M-x toggle-frame-maximized are available without having to define a function from below.

Frame parameter

This is the simplest approach, and works with CarbonEmacs and Aquamacs and the Yamamoto Mitsuharu version of Emacs 24. Use the toggle function:

(defun toggle-fullscreen ()
  "Toggle full screen"
  (interactive)
  (set-frame-parameter
     nil 'fullscreen
     (when (not (frame-parameter nil 'fullscreen)) 'fullboth)))

or use this to always use fullscreen:

(set-frame-parameter nil 'fullscreen 'fullboth)

Apparently the fullscreen functionality had not made it into Emacs 24 as of late 2012 but it is confirmed to be in Emacs 24.3.1 running on OS X 10.8.3 as of April 2013.

Maximizer

Maximizer is a free utility that brings Full Screen app mode to all Cocoa apps running in Mac OS X Lion 10.7, even if they don’t technically support the feature yet. It also works with Emacs from emacsformacosx.com. For more info go to article at osxdaily.com.

Patching the binary

To add the fullscreen functionality into Emacs, you can compile your own binary.

The procedure described on this page uses typester's patch from Dec 2009. Use M-x ns-toggle-fullscreen.

Patch for Emacs 23.1.95 pretest was posted Jan 2010, and contains instructions for using typester’s patch with newer versions of Emacs. (Recommended)

This blog post uses typester’s patch with newer versions of Emacs, and includes a download link to for a patched version of Emacs 24.0.50.

Emacs 23 Mac Port contains another patch; it’s unclear whether it’s related to the above.

homebrew builds emacs23 with the fullscreen patch:

brew install emacs --cocoa

Then use the function

ns-toggle-fullscreen

The patch is currently disabled for emacs24 (see the issue on GitHub).

There is a working homebrew formula that enables fullscreen mode under OS X Lion for the current git head versions (as of march 2012). Install using

brew install https://gist.github.com/raw/1946398/e7bbb52a4fe3ae0060e65df3d4a7462730ddc822/emacs.rb --force --HEAD --cocoa --use-git-head

Resizing the window

If your Emacs does not support fullscreen, it can be faked with the maxframe library, which resizes the window to approximately cover the entire screen. Use patched maxframe.el for Cocoa/Nextstep Emacs. You can see the original version from maxframe.el, which works for Windows, X11, and Carbon.

(require 'maxframe)
(defvar my-fullscreen-p t "Check if fullscreen is on or off")

(defun my-toggle-fullscreen ()
  (interactive)
  (setq my-fullscreen-p (not my-fullscreen-p))
  (if my-fullscreen-p
	  (restore-frame)
	(maximize-frame)))

(global-set-key (kbd "M-RET") 'my-toggle-fullscreen)

Linux and Windows

(defvar my-fullscreen-p t "Check if fullscreen is on or off")

(defun my-non-fullscreen ()
  (interactive)
  (if (fboundp 'w32-send-sys-command)
	  ;; WM_SYSCOMMAND restore #xf120
	  (w32-send-sys-command 61728)
	(progn (set-frame-parameter nil 'width 82)
		   (set-frame-parameter nil 'fullscreen 'fullheight))))

(defun my-fullscreen ()
  (interactive)
  (if (fboundp 'w32-send-sys-command)
	  ;; WM_SYSCOMMAND maximaze #xf030
	  (w32-send-sys-command 61488)
	(set-frame-parameter nil 'fullscreen 'fullboth)))

(defun my-toggle-fullscreen ()
  (interactive)
  (setq my-fullscreen-p (not my-fullscreen-p))
  (if my-fullscreen-p
	  (my-non-fullscreen)
	(my-fullscreen)))

See also

See also Fullscreen (just x-send-client-message for X Window).

Q&A

    • My Windows taskbar is vertical. Emacs gets confused and covers it partially. How can I make Emacs maximize every time I focus on it? I tried this, but the advice doesn’t seem to be invoked
(defadvice handle-switch-frame (after maximize-frame activate)
  "Maximize frame every time it receives focus, i.e. a switch-frame event."
  (w32-send-sys-command #xf030))