Commit 1816cd91 authored by Alan Coopersmith's avatar Alan Coopersmith

Add settable properties for middle mouse button emulation

Based on evdev's similar properties, including using the name "middle"
button, to avoid confusion with evdev's 3rd button emulation for
emulating the right button on a single button mouse.

Allows manual enable & disable at runtime.

Exports new xf86-mouse.pc & xf86-mouse-properties.h for property name
definitions.
Signed-off-by: Alan Coopersmith's avatarAlan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: default avatarAlexandr Shadchin <alexandr.shadchin@gmail.com>
Reviewed-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent 84090b15
......@@ -18,7 +18,7 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SUBDIRS = src man
SUBDIRS = include src man
MAINTAINERCLEANFILES = ChangeLog INSTALL
.PHONY: ChangeLog INSTALL
......@@ -31,6 +31,9 @@ ChangeLog:
dist-hook: ChangeLog INSTALL
# Provide an sdk location that is writable by this module
DISTCHECK_CONFIGURE_FLAGS = --with-sdkdir='$${includedir}/xorg'
if LINT
# Check source code with tools like lint & sparse
lint:
......
......@@ -57,6 +57,16 @@ AC_ARG_WITH(xorg-module-dir,
inputdir=${moduledir}/input
AC_SUBST(inputdir)
# X Server SDK location is required to install xf86-mouse-properties.h
# This location is also relayed in the xorg-mouse.pc file
sdkdir=`$PKG_CONFIG --variable=sdkdir xorg-server`
# Workaround overriding sdkdir to be able to create a tarball when user has no
# write permission in sdkdir. See DISTCHECK_CONFIGURE_FLAGS in Makefile.am
AC_ARG_WITH([sdkdir], [], [sdkdir="$withval"])
AC_SUBST([sdkdir])
# Work out which OS mouse driver we need to build
case $host_os in
linux*)
......@@ -78,6 +88,8 @@ DRIVER_NAME=mouse
AC_SUBST([DRIVER_NAME])
AC_CONFIG_FILES([Makefile
xf86-mouse.pc
include/Makefile
src/Makefile
man/Makefile])
AC_OUTPUT
sdk_HEADERS = xf86-mouse-properties.h
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef _XF86_MOUSE_PROPERTIES_H_
#define _XF86_MOUSE_PROPERTIES_H_
/* Middle mouse button emulation */
/* BOOL */
#define MOUSE_PROP_MIDBUTTON "Mouse Middle Button Emulation"
/* CARD32 */
#define MOUSE_PROP_MIDBUTTON_TIMEOUT "Mouse Middle Button Timeout"
#endif /* _XF86_MOUSE_PROPERTIES_H_ */
......@@ -125,12 +125,12 @@ cannot be auto-detected, the default value is 3. The maximum number is 24.
Enable/disable the emulation of the third (middle) mouse button for mice
which only have two physical buttons. The third button is emulated by
pressing both buttons simultaneously. Default: on, until a press of a
physical button 3 is detected.
physical button 3 is detected. Property: "Mouse Middle Button Emulation"
.TP 7
.BI "Option \*qEmulate3Timeout\*q \*q" integer \*q
Sets the timeout (in milliseconds) that the driver waits before deciding
if two buttons where pressed "simultaneously" when 3 button emulation is
enabled. Default: 50.
enabled. Default: 50. Property: "Mouse Middle Button Timeout"
.TP 7
.BI "Option \*qChordMiddle\*q \*q" boolean \*q
Enable/disable handling of mice that send left+right events when the middle
......
......@@ -19,7 +19,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AM_CFLAGS = $(CWARNFLAGS)
AM_CPPFLAGS = $(XORG_CFLAGS)
AM_CPPFLAGS = -I$(top_srcdir)/include $(XORG_CFLAGS)
# this is obnoxious:
# -module lets us name the module exactly how we want
......
......@@ -65,6 +65,7 @@
#include "exevents.h"
#include <X11/Xatom.h>
#include "xserver-properties.h"
#include "xf86-mouse-properties.h"
#include "compiler.h"
......@@ -139,6 +140,7 @@ static void ps2WakeupHandler(pointer data, int i, pointer LastSelectMask);
static void ps2BlockHandler(pointer data, struct timeval **waitTime,
pointer LastSelectMask);
#endif
static void Emulate3ButtonsSetEnabled(InputInfoPtr pInfo, Bool enable);
/* mouse autoprobe stuff */
static const char *autoOSProtocol(InputInfoPtr pInfo, int *protoPara);
......@@ -160,6 +162,10 @@ _X_EXPORT InputDriverRec MOUSE = {
#define RETRY_COUNT 4
/* Properties that can be set at runtime via xinput */
static Atom prop_mbemu = 0; /* Middle button emulation on/off property */
static Atom prop_mbtimeout = 0; /* Middle button timeout property */
/*
* Microsoft (all serial models), Logitech MouseMan, First Mouse, etc,
* ALPS GlidePoint, Thinking Mouse.
......@@ -1040,11 +1046,39 @@ static void MouseInitButtonLabels(Atom *btn_labels)
btn_labels[i] = unknown_btn;
}
static int
MouseSetProperty(DeviceIntPtr device, Atom atom,
XIPropertyValuePtr val, BOOL checkonly)
{
InputInfoPtr pInfo = device->public.devicePrivate;
MouseDevPtr pMse = pInfo->private;
if (atom == prop_mbemu)
{
if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
return BadMatch;
if (!checkonly)
Emulate3ButtonsSetEnabled(pInfo, *((BOOL*)val->data));
}
else if (atom == prop_mbtimeout)
{
if (val->format != 32 || val->size != 1 || val->type != XA_INTEGER)
return BadMatch;
if (!checkonly)
pMse->emulate3Timeout = *((CARD32*)val->data);
}
return Success;
}
static void
MouseInitProperties(DeviceIntPtr device)
{
InputInfoPtr pInfo = device->public.devicePrivate;
MouseDevPtr pMse = pInfo->private;
int rc;
#ifdef XI_PROP_DEVICE_NODE
const char *device_node =
......@@ -1076,6 +1110,32 @@ MouseInitProperties(DeviceIntPtr device)
XISetDevicePropertyDeletable(device, prop_btn_label, FALSE);
}
}
/* Middle button emulation - which this driver calls 3rd button emulation,
* but evdev's properties considers that to be simulating right button
* clicks from a one button mouse, which this driver does not currently
* support, so we use this name for better consistency.
*/
prop_mbemu = MakeAtom(MOUSE_PROP_MIDBUTTON, strlen(MOUSE_PROP_MIDBUTTON),
TRUE);
rc = XIChangeDeviceProperty(device, prop_mbemu, XA_INTEGER, 8,
PropModeReplace, 1,
&pMse->emulate3Buttons, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(device, prop_mbemu, FALSE);
prop_mbtimeout = MakeAtom(MOUSE_PROP_MIDBUTTON_TIMEOUT,
strlen(MOUSE_PROP_MIDBUTTON_TIMEOUT), TRUE);
rc = XIChangeDeviceProperty(device, prop_mbtimeout, XA_INTEGER, 32,
PropModeReplace, 1,
&pMse->emulate3Timeout, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(device, prop_mbtimeout, FALSE);
XIRegisterPropertyHandler(device, MouseSetProperty, NULL, NULL);
}
static void
......@@ -1965,6 +2025,32 @@ buttonTimer(InputInfoPtr pInfo)
return 0;
}
static void
Emulate3ButtonsSetEnabled(InputInfoPtr pInfo, Bool enable)
{
MouseDevPtr pMse = pInfo->private;
if (pMse->emulate3Buttons == enable)
return;
pMse->emulate3Buttons = enable;
if (enable) {
pMse->emulateState = 0;
pMse->emulate3Pending = FALSE;
pMse->emulate3ButtonsSoft = FALSE; /* specifically requested now */
RegisterBlockAndWakeupHandlers (MouseBlockHandler, MouseWakeupHandler,
(pointer) pInfo);
} else {
if (pMse->emulate3Pending)
buttonTimer(pInfo);
RemoveBlockAndWakeupHandlers (MouseBlockHandler, MouseWakeupHandler,
(pointer) pInfo);
}
}
static Bool
Emulate3ButtonsSoft(InputInfoPtr pInfo)
{
......@@ -1973,15 +2059,9 @@ Emulate3ButtonsSoft(InputInfoPtr pInfo)
if (!pMse->emulate3ButtonsSoft)
return TRUE;
pMse->emulate3Buttons = FALSE;
if (pMse->emulate3Pending)
buttonTimer(pInfo);
xf86Msg(X_INFO,"3rd Button detected: disabling emulate3Button\n");
RemoveBlockAndWakeupHandlers (MouseBlockHandler, MouseWakeupHandler,
(pointer) pInfo);
Emulate3ButtonsSetEnabled(pInfo, FALSE);
return FALSE;
}
......
sdkdir=@sdkdir@
Name: xf86-mouse
Description: X.Org mouse input driver for non-evdev OS'es
Version: @PACKAGE_VERSION@
Cflags: -I${sdkdir}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment