== Cross-platform methods ==

=== Fullscreen ===

==== Fullscreen mode ====
From the Emacs Linux [http://linuxmanpages.net/manpages/fedora14/man1/emacs.1.html man page] (command line "man emacs"), for maximized frame, and for complete full screen:

|| ##-fs, --fullscreen## || Make the first frame fullscreen ||

For example:

##emacs -mm [files]##

==== Toggle fullscreen ====
F11 will toggle the fullscreen by default in Emacs.

=== Hide bars ===
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)
}}}

=== Maximized ===
"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.

==== Maximized mode ====

From the Emacs Linux [http://linuxmanpages.net/manpages/fedora14/man1/emacs.1.html man page] (command line "man emacs"), for maximized frame, and for complete full screen:

|| ##-mm, --maximized## || Maximize the first frame, like "-fw -fh" (since Emacs 23.2) ||

For example:

##emacs -mm [files]##

==== Configuring maximized mode ====

=====Toogle maximization=====
Add this to the init file to toggle frame maximization with Alt+Return:

{{{
(global-set-key (kbd "M-RET") 'toggle-frame-maximized)
}}}

======Save the last frame toggle status======
* Add the following lines to your `init.el` file:
{{{
(desktop-save-mode 1)
(setq desktop-save t)
}}}
* Launch emacs-gtk.
* Manually maximize the Emacs frame.
* Close Emacs.
* The maximized frame state `(fullscreen . maximized)` will be saved in your `.emacs.desktop` file.

Note: Maximizing the Emacs frame via `.emacs.desktop` can cause a visible resizing effect that some users find distracting. Consider sharing your perspective in the emacs-devel mailing list discussion: [https://lists.gnu.org/archive/html/emacs-devel/2025-05/msg00070.html Introduce .early-init.desktop (inspired by early-init.el) -- needed to avoid visually distracting settings]

=====Automatic maximization at startup=====
From https://www.gnu.org/software/emacs/manual/html_mono/efaq.html#Start-Emacs-maximized

Run Emacs with the ‘--maximized’ command-line option or put the following form at the top of your early init file (see [https://www.gnu.org/software/emacs/manual/html_node/emacs/Early-Init-File.html Early Init File] in The GNU Emacs Manual).

{{{
(push '(fullscreen . maximized) default-frame-alist)
}}}

Note that while some customizations of default-frame-alist could have undesirable effects when modified in the early init file, it is okay to do it in this particular case. Adding it to the top of your normal init file will also work, but leads to a visible resizing of the frame [not window] that some find distracting. 

Addendum:

When Emacs loads the ##init file## in GNU/Linux, frame settings (##default-frame-alist##, ##initial-frame-alist##, ##set-frame-size##) are slightly deferred, which can lead to the distracting frame resizing upon startup.

The ##push## function adds an element to the beginning of a list. In this case, it adds the ##'(fullscreen . maximized)## list to the beginning of ##default-frame-alist##. Emacs recognizes the ##(fullscreen . maximized)## parameter and automatically applies it when creating the initial frame and any new frames opened from it. This means that after evaluating the ##push## expression, the initial frame will be maximized, and any subsequently opened frames will also be maximized by default. Alternatively, you can use other list manipulation functions like ##add-to-list## or ##custom-set-variables## to achieve the same result:

{{{
(add-to-list 'default-frame-alist '(fullscreen . maximized))
}}}

{{{
(custom-set-variables
 '(default-frame-alist '((fullscreen . maximized)))))
}}}

However, ##push## is generally considered the fastest approach because it doesn't evaluate its second argument, unlike ##add-to-list## and ##custom-set-variables##. By setting ##(fullscreen . maximized)## in ##default-frame-alist##, you can ensure that the initial frame and any new Emacs frames opened from it are maximized without needing to explicitly evaluate the expression each time.

==== Maximize/restore using library frame-cmds.el ====
[:frame-cmds.el]

Library <tt>[[frame-cmds.el]]</tt> 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. 

##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:

* `toggle-max-frame', `toggle-max-frame-horizontally', `toggle-max-frame-vertically'

* `maximize-frame', `maximize-frame-horizontally', `maximize-frame-vertically'

* `restore-frame', `restore-frame-horizontally', `restore-frame-vertically'

* `tile-frames', `tile-frames-horizontally', `tile-frames-vertically'


[new:TimRetout:2013-07-03 14:48 UTC]
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.


[:PlatformSpecific]
== Platform-specific methods ==

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

=== Mac OS X ===

====Fullscreen====

===== Emacs 24.4 =====

Use `ns-use-native-fullscreen' to get “native” fullscreen on OS X 10.7.

Both <code>M-x toggle-frame-fullscreen</code> or <code>M-x toggle-frame-maximized</code> 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 [http://emacsformacosx.com/ emacsformacosx.com]. For more info go to article at [http://osxdaily.com/2011/07/22/enable-full-screen-support-all-apps-os-x-lion-maximizer/ osxdaily.com].

===== Patching the binary =====

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

The procedure described on [http://www.stratospark.com/blog/2010/fullscreen_emacs_on_osx.html this page] uses [http://unknownplace.org/memo/2009/12/17/1/ typester's patch from Dec 2009].  Use <code>M-x ns-toggle-fullscreen</code>.

[http://www.sanityinc.com/full-screen-support-for-cocoa-emacs-on-osx 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)

[http://citizen428.net/archives/432 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.

[ftp://ftp.math.s.chiba-u.ac.jp/emacs/ Emacs 23 Mac Port] contains another patch; it's unclear whether it's related to the above.

[https://github.com/mxcl/homebrew 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 [https://github.com/mxcl/homebrew/issues/4085 the issue on GitHub]).

There is a [https://gist.github.com/1946398 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
}}}

==== Maximize ====

===== 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 [http://github.com/jmjeong/my-dot-emacs/blob/master/maxframe.el patched maxframe.el] for Cocoa/Nextstep Emacs. You can see the original version from [https://github.com/rmm5t/maxframe.el 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)
}}}

=== Windows ===

==== Fullscreen ====

===== 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.
This is bound to F11 by default (at least in 26.3).

===== Older versions =====
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 [http://www.ctrl-alt-del.com.au/CAD_TSUtils.htm 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.

===== 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 [http://www.martyn.se/code/emacs/darkroom-mode/ darkroom-mode]

===== Binary patch =====
Alternatively, a patch is available [https://github.com/erikcharlebois/patches/blob/master/emacs/w32_set_fullscreen.patch here] 
that makes the fullscreen frame parameter really fullscreen on Windows.

===== emacs-fullscreen-win32 =====
Another option is to use [https://bitbucket.org/alexander_manenko/emacs-fullscreen-win32/wiki/Home emacs-fullscreen-win32] project. It allows you to switch to/from full-screen mode.
====== Basic settings ======
* Add the following lines to your .emacs file:
{{{
(defun toggle-full-screen () (interactive) (shell-command "emacs_fullscreen.exe"))
(global-set-key [f11] 'toggle-full-screen)
}}}
* Compile main.c (or download compiled EXE [[https://bitbucket.org/alexander_manenko/emacs-fullscreen-win32/downloads/emacs_fullscreen.zip|here]]) and copy EXE file to the folder in your PATH (I use C:\Windows\system32).
* Now run Emacs and press F11 to switch into full-screen mode. Press F11 again to switch to windowed mode.
NOTE: This will not hide menu-bar, tool-bar, and scroll-bar.

====== 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)
}}}

Ps: in Windows System the right command to toggle full screen is (toggle-frame-fullscreen), change to that code in all the samples below.

====== 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 [[https://bitbucket.org/dacap/emacs-fullscreen-win32/changeset/866d015f9a7b|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 [https://github.com/amno1/toggle-fullscr-ew32 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 [https://github.com/amno1/toggle-fullscr-ew32/blob/master/toggle-fullscreen.el 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.

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

==== Maximizing window ====

=====Windows Registry=====
An alternative method involves adding an `Emacs.Geometry` entry to the [https://www.gnu.org/software/emacs/manual/html_mono/emacs.html#MS_002dWindows-Registry Windows Registry] settings, though this approach is not yet fully documented.

===== w32-send-sys-command =====
{{{
(if (fboundp 'w32-send-sys-command)
    ;; WM_SYSCOMMAND maximize #xf030
    (w32-send-sys-command 61488))
}}}

=== X Window System (X11) ===

==== Fullscreen ====

===== 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 programs =====

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

====== 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))
}}}

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

* install wmctrl (sudo apt-get install wmctrl)
* edit your .emacs and add:

{{{
(defun switch-full-screen ()
  (interactive)
  (shell-command "wmctrl -r :ACTIVE: -b toggle,fullscreen"))

(global-set-key [f11] 'switch-full-screen)
}}}

* To automatically execute the above commands when emacs is starting, complement them with:

{{{
(add-hook 'after-init-hook 'switch-full-screen)
}}}

==== Maximize ====

=====External programs=====

====== devilspie2 ======
{{{
mkdir -p ~/.config/devilspie2/

tee ~/.config/devilspie2/emacs.lua > /dev/null << EOF
-- From https://github.com/dsalt/devilspie2/blob/master/README.md#simple-script-examples :

-- Make Emacs (emacs or emacs-gtk) always start maximised.
win_class = get_class_instance_name()

debug_print("Window class: " .. win_class)

if win_class == "emacs" or win_class == "Emacs" then
  -- Emacs applies default window size etc. after a brief delay,
  -- potentially overriding devilspie2.
  --
  -- A brief pause (here, of 0.1s) ensures that devilspie2's actions on the
  -- window take effect after Emacs completes its initialisation. A shorter
  -- pause may work, or a longer one may be needed. Experiment! Could be
  -- that 'millisleep(10)' (0.01s) works well on one PC…?
  --
  -- If you prefer, you can have Emacs maximise its window (as in this
  -- example) via one of its configuration files - early-init.el, which is
  -- normally faster (and avoids a possible visual effect), or init.el –
  -- using this LISP statement:
  --   (push '(fullscreen .  maximized) default-frame-alist)
  --
  -- 'millisleep' is new to 0.46. The 0.1s delay for older versions:
  --   option 1:
  --     os.execute("sleep 0.1")
  --   option 2 (needs luaposix):
  --     nanosleep = require "posix.time".nanosleep
  --     nanosleep{tv_nsec=100e6}
  millisleep(100)
  maximise() -- maximize() for compatibility with <0.45
end
EOF
}}}

devilspie2 0.44 and earlier versions do not include a desktop file, requiring users to create one manually:
{{{
# Autostart devilspie2
mkdir -p "$HOME/.config/autostart/" # The directory does not exist by default
cd "$HOME/.config/autostart/" || exit
file="devilspie-2.desktop"
touch "$file"
desktop-file-edit \
--set-name="Devilspie 2" \
--set-comment="Perform scripted actions on windows as they are created" \
--set-key="Type" --set-value="Application" \
--set-key="Exec" --set-value="devilspie2" \
--set-key="X-MATE-Autostart-Delay" --set-value="0" \
"$file"
desktop-file-validate "$file"
}}}
* Log out and then log back into your desktop environment and start emacs, to make sure that devilspie2 autostarts and maximizes emacs.

====== wmctrl ======
If you want to bind F11 to toggle maximize the screen, here is what you need:

* install wmctrl (sudo apt-get install wmctrl)
* edit your .emacs and add:
{{{
(defun switch-full-screen ()
  (interactive)
  (shell-command "wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz"))
}}}

* Rather than using :ACTIVE: which can do the wrong thing when you start Emacs and other programs at the same time:
{{{
(defun switch-full-screen ()
  (interactive)
  (shell-command (concat "wmctrl -i -r " (frame-parameter nil 'outer-window-id) " -b toggle,maximized_vert,maximized_horz"))
}}}

* To automatically execute the above commands when emacs is starting, complement them with:

{{{
(add-hook 'after-init-hook 'switch-full-screen)
}}}

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


== Q&A ==

** Under Fvwm 2.5.23 I get a little band of background at the bottom
   of the screen --- any solution for that?  I have yet to try it with
   another WM.
** The solution is to add Style "*" <nowiki>ResizeHintOverride</nowiki> to your config
** This also occurs under Fluxbox 1.0; the current git repository fixes this problem
** Not a problem under KDE 3.5.7
