├── .gitignore ├── LICENSE.txt ├── Makefile ├── README.md └── hook.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2018 Andrew Gaul 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cc -Wall -shared -ldl -linput -fPIC hook.c -o hook.so 3 | 4 | clean: 5 | rm -f *.o *.so 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libinput-force-middle-click-emulation 2 | 3 | Force libinput to emulate a middle click when pressing left and right buttons 4 | simultaneously. This allows GNOME Wayland (and other Wayland compositors that 5 | do not expose libinput configuration) to configure the existing libinput 6 | functionality. 7 | 8 | ## Information for users of mutter version 3.36.1 or newer 9 | This is not needed anymore if you use `mutter` version 3.36.1 or newer. 10 | There it is possible to directly enable middle click emulation: 11 | ```bash 12 | gsettings set org.gnome.desktop.peripherals.mouse middle-click-emulation true 13 | ``` 14 | 15 | ## Installation 16 | 17 | Build `hook.so` then configure `libinput` to `LD_PRELOAD` it: 18 | 19 | ```bash 20 | make 21 | echo 'export LD_PRELOAD="$LD_PRELOAD /path/to/hook.so"' | sudo tee -a /etc/profile.d/libinput.sh 22 | ``` 23 | 24 | Log out and log in to enable. 25 | 26 | ## References 27 | 28 | * [GNOME mutter issue](https://gitlab.gnome.org/GNOME/mutter/issues/238) 29 | * [libinput documentation](https://wayland.freedesktop.org/libinput/doc/latest/middle-button-emulation.html) 30 | * Inspired by [scroll-emulation](https://github.com/PeterCxy/scroll-emulation) 31 | 32 | ## License 33 | 34 | * MIT 35 | -------------------------------------------------------------------------------- /hook.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #include 3 | #include 4 | 5 | typedef const char *(*orig_get_name_t)(struct libinput_device *device); 6 | 7 | const char *libinput_device_get_name(struct libinput_device *device) 8 | { 9 | libinput_device_config_middle_emulation_set_enabled(device, LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); 10 | orig_get_name_t orig_get_name; 11 | orig_get_name = (orig_get_name_t) dlsym(RTLD_NEXT, "libinput_device_get_name"); 12 | return orig_get_name(device); 13 | } 14 | --------------------------------------------------------------------------------