After having the unnecessary scroll-, tool- and foo-bars removed it is nice to toggle emacs fullscreen with a keyboard shortcut.
The following code pasted into the .emacs file will do the job under Ubuntu, using wmctrl. It works with a lot of desktop managers (Xfce, fluxbox, Gnome at I tried at least). If it is not installed
sudo aptitude install wmctrl
The full screen mode is based on a code snippet I found online. The comments in the .emacs file gave credit to the emacswiki and Steven Poole for the code.
First define a lisp function calling wmctrl:
(defun djcb-full-screen-toggle ()
(interactive)
(shell-command "wmctrl -r :ACTIVE: -b toggle,fullscreen"))
and then a keybinding to the function
(DefGlobKey "H-f" 'djcb-full-screen-toggle)
In this example toggle fullscreen is bound to H-f which means pressing the Hyper key and f. You have to customize it to your needs.
Genius! Exactly what I was looking for!
edit: I just changed the key binding to [f11] instead of “H-f” to be consistent with other applications I am running.
…and used (global-set-key…) instead of (DefGlobKey…)
Thanks a lot, exactly what I was looking for. The –fullscreen option gets rid of the echo area, thus is pretty useless. Just a stupid question: how can I make fullscreen the default when starting? Thanks a lot.
Welcome
No stupid question. I never thought about it myself…
My solution is not emacs’ish, rather bash’ish, so there might be a more elegant way.
Anyway. Including
(shell-command "wmctrl -r :ACTIVE: -b add,fullscreen")in your .emacs file gives you fullscreen mode on startup and than you can toggle back afterwards as you are used to …
You should be able to just use your newly defined function name. For instance, if you used the name mentioned above in your defun: djcb-full-screen-toggle, you can just add that somewhere after your defun to be resolved during startup. So add
(djcb-full-screen-toggle)
after the stuff above.
That is then the more emacs’ish, elegant and straightforward way to do it.
Thanks a lot. I will update the post…