From bab9d1fa18f57616d78a29242cdd31faa372947b Mon Sep 17 00:00:00 2001 From: Alex Tanskanen Date: Mon, 13 Jan 2020 15:23:20 +0100 Subject: [PATCH] Add emulated middle mouse button Not every mouse has three buttons e.g. laptops. Some OS might not have support for middle mouse button emulation. This commit adds emulation for middle mouse button when pressing both left and right mouse button simultaneously. --- vncviewer/CMakeLists.txt | 1 + vncviewer/EmulateMB.cxx | 289 ++++++++++++++++++++++++++++++++++++ vncviewer/EmulateMB.h | 47 ++++++ vncviewer/OptionsDialog.cxx | 8 + vncviewer/OptionsDialog.h | 1 + vncviewer/Viewport.cxx | 37 +++-- vncviewer/Viewport.h | 7 +- vncviewer/parameters.cxx | 5 + vncviewer/parameters.h | 1 + vncviewer/vncviewer.man | 5 + 10 files changed, 384 insertions(+), 17 deletions(-) create mode 100644 vncviewer/EmulateMB.cxx create mode 100644 vncviewer/EmulateMB.h diff --git a/vncviewer/CMakeLists.txt b/vncviewer/CMakeLists.txt index 3c186463..caf6d7a8 100644 --- a/vncviewer/CMakeLists.txt +++ b/vncviewer/CMakeLists.txt @@ -6,6 +6,7 @@ set(VNCVIEWER_SOURCES menukey.cxx CConn.cxx DesktopWindow.cxx + EmulateMB.cxx UserDialog.cxx ServerDialog.cxx Surface.cxx diff --git a/vncviewer/EmulateMB.cxx b/vncviewer/EmulateMB.cxx new file mode 100644 index 00000000..22332745 --- /dev/null +++ b/vncviewer/EmulateMB.cxx @@ -0,0 +1,289 @@ +/* Copyright 2020 Alex Tanskanen for Cendio AB + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +/* + * Based on xf86-input-evdev + * + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. + * Copyright 1993 by David Dawes + * Copyright 2002 by SuSE Linux AG, Author: Egbert Eich + * Copyright 1994-2002 by The XFree86 Project, Inc. + * Copyright 2002 by Paul Elliott + * (Ported from xf86-input-mouse, above copyrights taken from there) + * Copyright © 2008 University of South Australia + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of the authors + * not be used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. The authors make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include + +#include "parameters.h" +#include "i18n.h" +#include "EmulateMB.h" + +/* + * Lets create a simple finite-state machine for 3 button emulation: + * + * We track buttons 1 and 3 (left and right). There are 11 states: + * 0 ground - initial state + * 1 delayed left - left pressed, waiting for right + * 2 delayed right - right pressed, waiting for left + * 3 pressed middle - right and left pressed, emulated middle sent + * 4 pressed left - left pressed and sent + * 5 pressed right - right pressed and sent + * 6 released left - left released after emulated middle + * 7 released right - right released after emulated middle + * 8 repressed left - left pressed after released left + * 9 repressed right - right pressed after released right + * 10 pressed both - both pressed, not emulating middle + * + * At each state, we need handlers for the following events + * 0: no buttons down + * 1: left button down + * 2: right button down + * 3: both buttons down + * 4: emulate3Timeout passed without a button change + * Note that button events are not deltas, they are the set of buttons being + * pressed now. It's possible (ie, mouse hardware does it) to go from (eg) + * left down to right down without anything in between, so all cases must be + * handled. + * + * a handler consists of three values: + * 0: action1 + * 1: action2 + * 2: new emulation state + * + * action > 0: ButtonPress + * action = 0: nothing + * action < 0: ButtonRelease + * + * The comment preceeding each section is the current emulation state. + * The comments to the right are of the form + *