Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

FullScreen

Cross-platform methods

Fullscreen

Fullscreen mode

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

-fs, --fullscreenMake 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 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)

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)
Automatic maximization at startup

Probably the simplest way to configure fullscreen or maximized mode in Emacs is to customize the default-frame-alist variable. The default-frame-alist is a list of property lists that specify the initial appearance of Emacs frames. Each property list contains a set of key-value pairs that define frame properties. To maximize the initial frame and any new frames opened from it by default, you can add the (fullscreen . maximized) property to default-frame-alist using the push function:

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

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.

To avoid the slightly distracting visual effect

A deviant graphical behavior in Emacs (GTK) compared to the vast majority of GUI programs, is that Emacs starting with its default frame size and then switching to fullscreen when you maximize it (from now on referred to as the “frame effect”).

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 “frame effect” upon startup.

The early init file is processed prior to the initialization of the regular init file, allowing the frame settings to take precedence. To ensure that Emacs starts maximized without first displaying the default frame size, it is necessary to add the relevant code to the early init file:

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

This code has been successfully tested in various environments, including:

  • GNU/Linux (both X11 and Wayland)
  • macOS
  • Windows

Remember to add the code to the top of early-init.el if you have created it earlier to prevent any load delay.

While some customizations of ‘default-frame-alist’ could have undesirable effects when modified in early-init.el, it is generally safe to do so in this particular case.

In essence, the code above will make Emacs behave as if you had launched it with the emacs --maximize argument, automatically maximizing the window each time you open Emacs. This eliminates the slightly distracting visual effect that can occur when Emacs loads the frame settings after startup.

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.

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’

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.

Mac OS X

Fullscreen

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

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

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

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 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 “*” ResizeHintOverride 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