summaryrefslogtreecommitdiffhomepage
path: root/tech/xahkeys.mdwn
blob: 9e80d1a78ee375fb39081481e849c16521ec5a58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
[[!meta title="Cross-platform window management key bindings for Emacs users" date="2015-06-10" updated="2015-06-10"]]

I have figured out a set of window management key bindings which can be
implemented under both X11 on GNU/Linux systems and Microsoft Windows.
This lets you have

*   **run-or-raise keys** for your most commonly used programs (that is:
    press one key to either launch the program or switch to its window);
*   **AeroSnap-style tiling**;
*   **focus-follow-mouse** and
*   **workspaces**

... all with **the same bindings** on your GNU/Linux machine and your
Windows machine.

I find that this means I don't need a complicated and fragile tiling
window manager configuration that I can't use on Windows and that
doesn't work very well with Emacs anyway. See the
[rationale](#rationale) for more.

*Terminological note:* When I say 'window' I mean what most people think
of as a window, that is, what Emacs users generally call a 'frame'.

[[!toc]]

The bindings
============

s-<left>/<right>
:   Tile window to left or right of screen, Windows 7 AeroSnap style

s-<up>
:   Maximise window

s-<down>
:   Minimise window

s-l
:   lock screen

C-M-<arrow>
:   Move to a different workspace

C-M-S-<arrow>
:   Move current window to a different workspace

F9
:   Switch to Emacs

F10
:   Switch to terminal

F11
:   Kill current window

F12
:   Switch to web browser

S-F{9, ..., 12}
:   Switch to other frequently used applications

Setting up the bindings
=======================

For now these are just rough notes; how you implement the bindings is up
to you. The important thing is that the bindings really do work
cross-platform.

X11 (e.g. GNU/Linux)
--------------------

There are numerous ways to do this. Here is how I do it:

1.  Set up the AeroSnap, maximise, minimise, screen lock and workspace
    bindings using my window manager's configuration dialogue (in my
    case, XFCE's window manager Xfwm).

2.  Bind the remaining keys with xbindkeys: here is my [xbindkeys
    configuration
    file](https://github.com/spwhitton/dotfiles/blob/master/.xbindkeysrc),
    and here is [my run-or-raise
    script](https://github.com/spwhitton/dotfiles/blob/master/bin/xlaunch).
    If you're just starting out, you should probably try something like
    [jumpapp](https://github.com/mkropat/jumpapp).

Microsoft Windows
-----------------

The keys for AeroSnap, maximise, minimise and screen lock are built into
Windows.

### Run-or-raise bindings

See [my AutoHotKey
script](https://github.com/spwhitton/dotfiles/blob/master/bin/sariulahk.ahk)
for my methodology. It's quite specific as it hardcodes a bunch of paths
I use at work; please see [the
article](http://lifehacker.com/5468862/create-a-shortcut-key-for-restoring-a-specific-window)
whose code I started from.

### focus-follow-mouse

Open the registry editor and go to the key `HKCU\Control
Panel\Desktop\UserPreferencesMask`. Set the first bit to 1 and the
seventh bit to 0. ([MSDN
reference](https://technet.microsoft.com/en-us/library/cc957204.aspx))

### Workspaces

Install [VirtuaWin](http://virtuawin.sourceforge.net/) and configure the
above bindings graphically.

Rationale
=========

Tiling window managers such as [dwm](http://dwm.suckless.org/) try to
make window management smoother and more automatic. They do this by
arranging windows automatically for the user, and by binding keys that
let the user switch between windows, open new windows and control the
tiling without thinking too much about it. The user is freed up to
concentrate more on the contents of their windows.

Unfortunately, Emacs doesn't fit naturally into a tiling window manager
workflow. Emacs windows generally need to be fullscreen because lots of
features of Emacs split the window into two. Due to this splitting, and
unlike other text-based software such as programs made with ncurses,
Emacs windows respond poorly to being shrunk and enlarged at regular
intervals by the tiling window manager.[[!template id=note text="""
There have been attempts to make Emacs always open new windows instead of splitting its windows. An older and more complicated setup
is [One On One Emacs](http://emacswiki.org/emacs/OneOnOneEmacs)
and a more recent package is
[frames-only-mode](http://compsoc.man.ac.uk/~shep/tearing-out-the-emacs-window-manager.html).
The author of the latter tells me, to my surprise, that he doesn't
find himself constantly needing to tweak his Emacs configuration to
stop cranky Emacs features he brings into use splitting windows
instead of making new ones.
"""]]

A second problem for Emacs users is that Emacs is cross-platform, but
tiling window managers aren't. If Emacs is the centre of your workflow
and you use it on more than one operating system, you need your window
management bindings and behaviour to work the same on the different OSs.
Using a tiling window manager on GNU/Linux with Emacs carefully
integrated---see the footnote to the previous paragraph---but then
losing this functionality when switching to Microsoft Windows is
jarring.

The key bindings described in this document give you some of the
benefits of heavily customised tiling window managers without tying your
window management workflow to a particular operating system and without
trying to squash Emacs into a window management philosophy it is not
suited for.

Personal background
-------------------

I tried a succession of different tiling window managers when vim was my
editor, but I stopped using them after I switched to Emacs and found
after a time that I didn't need all those terminal windows I used to
have open. I then came across [this
article](http://xahlee.info/linux/why_tiling_window_manager_sucks.html)
by Xah Lee who argues that run-or-raise bindings are all that you really
need. I also had to start using Microsoft Windows 7 at work and found
that AeroSnap provides enough tiling for most purposes, if you give
yourself workspaces. Many people have written about the benefits of
run-or-raise shortcuts, which I first used under
[StumpWM](https://stumpwm.github.io/).