Patch scrolling back in suckless ST terminal to support mouse wheel

It is not that simple. This question occasionally arises when someone wants left/right scrolling for a mouse trackball.

On the left column of the tables is an X event. Those are limited to combinations of predefined symbols.

Button4 and Button5 are mentioned because those are conventionally used to pass the mouse wheel events. That has been the case for quite a while; there was a resource file used before modifying xterm in 1999 (patch #120) to make this a built-in feature.

The possible X events are laid out in C header files — X.h — and tables in the X source code; no wheel mouse events are provided for as such. For instance, there is a table in the X Toolkit library which lists all of the possibilities (for clients using X Toolkit such as xterm). xev uses the header-definitions.

If X were to support wheel mouse events in a different way, it would probably use new function calls for this purpose since the existing information may be packed into bit-fields in a way that precludes easy extensibility.


There is now a standalone program scroll that provides scrollback buffer for any terminal emulator. At the time of writing this answer, it is still in an experimental state, a lot of bugs are expected. In spite of that, it already handles scrollback better than the scrollback patches for st. E.g. resizing the terminal will wrap previous output instead of cut off and lose them.

To enable it, first of course download/clone the source code from suckless website and build it locally.

Then modify this line in config.def.h of st (you have to fetch the recent git commits to get support for scroll)

char *scroll = NULL;

to

char *scroll = "/path/to/scroll";

Now rebuild st, and run st. It will automatically use scroll to provide the scrollback buffer.

As stated in the manual, another way without modifying st's course code is to run st with the following command after you have installed both st and scroll:

/path/to/st -e /path/to/scroll /bin/sh

Tags:

Unix

C

X11

Terminal