gnome-terminal, the default terminal on Gnome desktops, has an annoying featurebug where mouse interactions are relayed to applications running inside the terminal (e.g., vim, htop), and there’s no way to disable it. I don’t know about you, but I think this is a mistake.

Based on the discussion on Gnome’s gitlab instance (Add option to disable mouse handling in gnome-terminal) it looks like there’s no intention to disable this featurebug, leaving us with only one option: rebuild from source. Here’s a quick rundown describing how to do that.

Note: I’m running Linux Mint, an Ubuntu/Debian derivative. The concept will be the same for all Debian-based systems but the specific file names and versions may differ.

Note2: This does not disable copy-on-select or paste-on-middleclick!

Rebuild gnome-terminal without mouse click/drag support

  1. Add source repositories.

Open “Software Sources” (for me this is under “Administration”), enable “Source code repositories”, and update your APT cache. Alternatively, find your distro’s deb-src value and add it to /etc/apt/sources.list or /etc/apt/sources.list.d.

  1. Install build-essential, debhelper: sudo apt install build-essential debhelper and then the package dependencies: sudo apt-get build-dep libvte-2.9.1-0.

  2. Download the source for libvte (the dependency that handles the mouse):

mkdir ~/src
cd ~/src

# dpkg -l | grep ' libvte' to find the package, for me it is:
apt-get source libvte-2.91-0:amd64
  1. Go in to the source directory and fix the featurebug in src/vteseq.cc.

For me, the source is in vte2.91-0.68.0. There, edit src/vteseq.cc. Find Terminal::update_mouse_protocol as suggested in the Gitlab link and comment out the entire if/else block. Then insert m_mouse_tracking_mode = MouseTrackingMode::eNONE; at the top of the function. Save, quit.

Here’s the patch:

--- vte2.91-0.68.0.orig/src/vteseq.cc
+++ vte2.91-0.68.0/src/vteseq.cc
@@ -462,7 +462,9 @@ Terminal::set_mode_ecma(vte::parser::Seq
 void
 Terminal::update_mouse_protocol() noexcept
 {
-        if (m_modes_private.XTERM_MOUSE_ANY_EVENT())
+        m_mouse_tracking_mode = MouseTrackingMode::eNONE;
+
+        /* if (m_modes_private.XTERM_MOUSE_ANY_EVENT())
                 m_mouse_tracking_mode = MouseTrackingMode::eALL_MOTION_TRACKING;
         else if (m_modes_private.XTERM_MOUSE_BUTTON_EVENT())
                 m_mouse_tracking_mode = MouseTrackingMode::eCELL_MOTION_TRACKING;
@@ -473,7 +475,7 @@ Terminal::update_mouse_protocol() noexce
         else if (m_modes_private.XTERM_MOUSE_X10())
                 m_mouse_tracking_mode = MouseTrackingMode::eSEND_XY_ON_CLICK;
         else
-                m_mouse_tracking_mode = MouseTrackingMode::eNONE;
+                m_mouse_tracking_mode = MouseTrackingMode::eNONE; */

         m_mouse_smooth_scroll_delta = 0.0;
  1. Commit the change locally.

Run dpkg-commit.

This will first let you name the patch – I chose disable-mouse.patch. Then an editor that will allow you to specify a headline and description of your change. Go ahead and type whatever; it doesn’t matter. Save, quit.

  1. Rebuild the package.

Run dpkg-buildpackage -rfakeroot -us -uc.

The -us and -uc flags disable code signing. Without that, you’ll be asked to provide the secret key of the official Debian contributors, which you probably don’t have.

  1. Install the updated packages.

The buildpackage command will generate a handful of .deb files. You can find them in ~/src – here’s mine:

dpk@desktop:~/src$ ls -lt *.deb
-rw-r--r-- 1 dpk dpk  65438 Jul 30 09:32 libvte-2.91-doc_0.68.0-1ubuntu0.1_all.deb
-rw-r--r-- 1 dpk dpk  59658 Jul 30 09:32 libvte-2.91-dev_0.68.0-1ubuntu0.1_amd64.deb
-rw-r--r-- 1 dpk dpk 232968 Jul 30 09:32 libvte-2.91-0_0.68.0-1ubuntu0.1_amd64.deb
-rw-r--r-- 1 dpk dpk  72522 Jul 30 09:32 libvte-2.91-common_0.68.0-1ubuntu0.1_amd64.deb

You can install these with sudo dpkg -i libvte-2.91*deb.

  1. Log out and log back in.

The easiest way to “activate” the change is to log out and log back in. You can probably restart gnome-terminal-server, instead, if you want, but eh.

  1. Test.

Open htop, witness the ability to select text!

Hope this helps someone out there. If I’m missing a step (certainly possible) please let me know. Making this configurable at runtime is left as an exercise for the reader (I might come back to this later if I end up needing it.) I do realize this is ironic because I complained about the inability to disable the feature at runtime.