Fullscreen toggle with Emacs Shortcuts

16 08 2009

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.

About these ads

Actions

Information

7 responses

6 07 2010
nodnarb

Genius! Exactly what I was looking for!

6 07 2010
nodnarb

edit: I just changed the key binding to [f11] instead of “H-f” to be consistent with other applications I am running.

6 07 2010
nodnarb

…and used (global-set-key…) instead of (DefGlobKey…)

15 11 2010
dani

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.

16 11 2010
rforge

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 …

16 11 2010
nodnarb

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.

16 11 2010
rforge

That is then the more emacs’ish, elegant and straightforward way to do it.

Thanks a lot. I will update the post…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: