Restoring GTK3 Typeahead in Ubuntu 19.10 Eoan Ermine

As someone who cut their digital teeth on computers with function keys, the keyboard is far and away my favorite and preferred input device. Mice and trackpads are fine, but I type like a demon, so if I can get somewhere without having to move my hands off the keyboard, all the better for productivity!

One major pet peeve of mine with the past few releases of GNOME Shell has to do with the GTK file dialogue’s keyboard behaviors. Where once typing within the list would automatically move focus to the first matching item — “typeahead” — it now reductively filters the list so that unmatched entries are removed from view.

Let’s illustrate this really quick. Assume you’ve opened a file dialogue and it shows the following entries:

 directory_one
 directory_two
 image.jpg
 image.png
 something.txt

Now assume you’ve typed the string “dir”.

With typeahead behaviors, the list remains the same, but the first entry gains focus:

[directory_one]
 directory_two
 image.jpg
 image.png
 something.txt

Typing “dir” again would move to the second match:

 directory_one
[directory_two]
 image.jpg
 image.png
 something.txt

But with reductive filtering behaviors, the list is instead truncated without any changes to focus:

 directory_one
 directory_two

I can definitely envision a use case where reductive filtering would be helpful, but I type so much faster than GNOME paints, the filter UI is completely unusable.

This might not be a problem for you, in which case you can skip the rest of this tutorial! For its part, GNOME clearly prefers this approach. They no longer expose any settings to toggle typeahead back on.

But thankfully, if you do miss the old ways, restoring the relevant code is just patch away.

Rebuilding GTK

To alter GTK’s behaviors, you need to modify its source and rebuild the affected packages. This sounds very technical, but Debian-based distributions like Ubuntu make this process quite easy.

Before you get started, make sure you have enabled the appropriate source repositories in your /etc/apt/sources.list. You may well be using different mirrors, but it should look something like this:

# The compiled stuff.
deb https://mirrors.edge.kernel.org/ubuntu/ eoan main universe restricted multiverse
# The source stuff.
deb-src https://mirrors.edge.kernel.org/ubuntu/ eoan main universe restricted multiverse

Now go ahead and grab all of the source materials you’ll need:

# Make sure your mirrors are up-to-date.
sudo apt-get update

# Make sure you have the build dependencies installed. Feel free
# to save this list of new packages somewhere so you can remove
# them after you're done building. Building GTK requires a lot
# of crap you'll probably never need again. Haha.
sudo apt-get build-dep gtk+3.0

# Make yourself a scratch folder and download the sources to it.
mkdir /tmp/gtk3
cd /tmp/gtk3
apt-get source gtk+3.0

# You'll also need a patch to modify the relevant parts of the
# GTK codebase to restore typeaheadness. The AUR package
# gtk3-typeahead contains a patch that works for several GTK
# releases, including those used by Ubuntu Disco Dingo and Eoan
# Ermine. AUR sources can be fetched with git:
git clone https://aur.archlinux.org/gtk3-typeahead.git patch

Now that you have all the goods, it’s just a matter of patching and building!

# Move to the source directory.
cd /tmp/gtk3/gtk+3.0-3.24.12

# Apply the patch from AUR.
patch gtk/gtkfilechooserwidget.c -i ../patch/typeahead.patch

# Rebuild it.
sudo dpkg-buildpackage -b

Easy, no?

GTK is a rather large library so it will probably take a while to build. Go ahead and grab yourself a sandwich if you’re hungry.

Upgrade!

Once the build process has completed, you’ll find a handful of .deb packages under /tmp/gtk3 (one level up from where you ran the build command).

All you need to do is install the ones you need — all GTK packages will have been rebuilt, even ones not installed on your system — and reboot to ensure running applications reference the right GTK functionality.

# If you want to clean up the build dependencies installed
# earlier, you can safely do so now.
sudo apt-get purge -y unwanted-thing other-thing…

# Install your rebuilt GTK packages:
cd /tmp/gtk3
sudo dpkg -i something.deb something-else.deb…

# Reboot once.
sudo reboot

If you aren’t sure which GTK-related binaries are currently installed on your system, you can generate digestible reference lists like:

apt list --installed | grep gail
apt list --installed | grep gtk

Rinse and Repeat

Ubuntu does not push updated GTK packages to its repositories very often, but if one day you happen to notice the file dialogue is back to filter fuckery, just repeat the steps in this tutorial to re-rebuild it.