summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnas Nashif <anas.nashif@intel.com>2012-11-06 21:15:01 -0800
committerAnas Nashif <anas.nashif@intel.com>2012-11-06 21:15:01 -0800
commit46f77ab436a73361e7d37f69bb77e6753b407a2f (patch)
tree97b3c3cfc4e2fb93353d8a36d82d41f23a50fa91 /src
downloadxf86-input-evdev-46f77ab436a73361e7d37f69bb77e6753b407a2f.tar.gz
xf86-input-evdev-46f77ab436a73361e7d37f69bb77e6753b407a2f.tar.bz2
xf86-input-evdev-46f77ab436a73361e7d37f69bb77e6753b407a2f.zip
Imported Upstream version 2.7.3upstream/2.7.3upstream
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am43
-rw-r--r--src/Makefile.in627
-rw-r--r--src/apple.c312
-rw-r--r--src/draglock.c318
-rw-r--r--src/emuMB.c391
-rw-r--r--src/emuThird.c416
-rw-r--r--src/emuWheel.c480
-rw-r--r--src/evdev.c2969
-rw-r--r--src/evdev.h302
9 files changed, 5858 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..804ef73
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,43 @@
+# Copyright 2005 Adam Jackson.
+#
+# 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
+# on the rights to use, copy, modify, merge, publish, distribute, sub
+# license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+# ADAM JACKSON 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.
+
+
+# this is obnoxious:
+# -module lets us name the module exactly how we want
+# -avoid-version prevents gratuitous .0.0.0 version numbers on the end
+# _ladir passes a dummy rpath to libtool so the thing will actually link
+# TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
+
+AM_CFLAGS = $(XORG_CFLAGS) $(CWARNFLAGS)
+AM_CPPFLAGS =-I$(top_srcdir)/include
+
+@DRIVER_NAME@_drv_la_LTLIBRARIES = @DRIVER_NAME@_drv.la
+@DRIVER_NAME@_drv_la_LDFLAGS = -module -avoid-version
+@DRIVER_NAME@_drv_la_LIBADD = $(MTDEV_LIBS) $(UDEV_LIBS)
+@DRIVER_NAME@_drv_ladir = @inputdir@
+
+@DRIVER_NAME@_drv_la_SOURCES = @DRIVER_NAME@.c \
+ @DRIVER_NAME@.h \
+ emuMB.c \
+ emuThird.c \
+ emuWheel.c \
+ draglock.c \
+ apple.c
+
diff --git a/src/Makefile.in b/src/Makefile.in
new file mode 100644
index 0000000..fa41413
--- /dev/null
+++ b/src/Makefile.in
@@ -0,0 +1,627 @@
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+# Copyright 2005 Adam Jackson.
+#
+# 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
+# on the rights to use, copy, modify, merge, publish, distribute, sub
+# license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+# ADAM JACKSON 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.
+
+# this is obnoxious:
+# -module lets us name the module exactly how we want
+# -avoid-version prevents gratuitous .0.0.0 version numbers on the end
+# _ladir passes a dummy rpath to libtool so the thing will actually link
+# TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = src
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+ test -z "$$files" \
+ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+ $(am__cd) "$$dir" && rm -f $$files; }; \
+ }
+am__installdirs = "$(DESTDIR)$(@DRIVER_NAME@_drv_ladir)"
+LTLIBRARIES = $(@DRIVER_NAME@_drv_la_LTLIBRARIES)
+am__DEPENDENCIES_1 =
+@DRIVER_NAME@_drv_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_1)
+am_@DRIVER_NAME@_drv_la_OBJECTS = @DRIVER_NAME@.lo emuMB.lo \
+ emuThird.lo emuWheel.lo draglock.lo apple.lo
+@DRIVER_NAME@_drv_la_OBJECTS = $(am_@DRIVER_NAME@_drv_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+@DRIVER_NAME@_drv_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+ $(AM_CFLAGS) $(CFLAGS) $(@DRIVER_NAME@_drv_la_LDFLAGS) \
+ $(LDFLAGS) -o $@
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+SOURCES = $(@DRIVER_NAME@_drv_la_SOURCES)
+DIST_SOURCES = $(@DRIVER_NAME@_drv_la_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ADMIN_MAN_DIR = @ADMIN_MAN_DIR@
+ADMIN_MAN_SUFFIX = @ADMIN_MAN_SUFFIX@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+APP_MAN_DIR = @APP_MAN_DIR@
+APP_MAN_SUFFIX = @APP_MAN_SUFFIX@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CHANGELOG_CMD = @CHANGELOG_CMD@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CWARNFLAGS = @CWARNFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
+DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
+DRIVER_NAME = @DRIVER_NAME@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+FILE_MAN_DIR = @FILE_MAN_DIR@
+FILE_MAN_SUFFIX = @FILE_MAN_SUFFIX@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_CMD = @INSTALL_CMD@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIB_MAN_DIR = @LIB_MAN_DIR@
+LIB_MAN_SUFFIX = @LIB_MAN_SUFFIX@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MAN_SUBSTS = @MAN_SUBSTS@
+MISC_MAN_DIR = @MISC_MAN_DIR@
+MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
+MKDIR_P = @MKDIR_P@
+MTDEV_CFLAGS = @MTDEV_CFLAGS@
+MTDEV_LIBS = @MTDEV_LIBS@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
+STRIP = @STRIP@
+UDEV_CFLAGS = @UDEV_CFLAGS@
+UDEV_LIBS = @UDEV_LIBS@
+VERSION = @VERSION@
+XI22_CFLAGS = @XI22_CFLAGS@
+XI22_LIBS = @XI22_LIBS@
+XORG_CFLAGS = @XORG_CFLAGS@
+XORG_LIBS = @XORG_LIBS@
+XORG_MAN_PAGE = @XORG_MAN_PAGE@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+inputdir = @inputdir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sdkdir = @sdkdir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AM_CFLAGS = $(XORG_CFLAGS) $(CWARNFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir)/include
+@DRIVER_NAME@_drv_la_LTLIBRARIES = @DRIVER_NAME@_drv.la
+@DRIVER_NAME@_drv_la_LDFLAGS = -module -avoid-version
+@DRIVER_NAME@_drv_la_LIBADD = $(MTDEV_LIBS) $(UDEV_LIBS)
+@DRIVER_NAME@_drv_ladir = @inputdir@
+@DRIVER_NAME@_drv_la_SOURCES = @DRIVER_NAME@.c \
+ @DRIVER_NAME@.h \
+ emuMB.c \
+ emuThird.c \
+ emuWheel.c \
+ draglock.c \
+ apple.c
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign src/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-@DRIVER_NAME@_drv_laLTLIBRARIES: $(@DRIVER_NAME@_drv_la_LTLIBRARIES)
+ @$(NORMAL_INSTALL)
+ test -z "$(@DRIVER_NAME@_drv_ladir)" || $(MKDIR_P) "$(DESTDIR)$(@DRIVER_NAME@_drv_ladir)"
+ @list='$(@DRIVER_NAME@_drv_la_LTLIBRARIES)'; test -n "$(@DRIVER_NAME@_drv_ladir)" || list=; \
+ list2=; for p in $$list; do \
+ if test -f $$p; then \
+ list2="$$list2 $$p"; \
+ else :; fi; \
+ done; \
+ test -z "$$list2" || { \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(@DRIVER_NAME@_drv_ladir)'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(@DRIVER_NAME@_drv_ladir)"; \
+ }
+
+uninstall-@DRIVER_NAME@_drv_laLTLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @list='$(@DRIVER_NAME@_drv_la_LTLIBRARIES)'; test -n "$(@DRIVER_NAME@_drv_ladir)" || list=; \
+ for p in $$list; do \
+ $(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(@DRIVER_NAME@_drv_ladir)/$$f'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(@DRIVER_NAME@_drv_ladir)/$$f"; \
+ done
+
+clean-@DRIVER_NAME@_drv_laLTLIBRARIES:
+ -test -z "$(@DRIVER_NAME@_drv_la_LTLIBRARIES)" || rm -f $(@DRIVER_NAME@_drv_la_LTLIBRARIES)
+ @list='$(@DRIVER_NAME@_drv_la_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
+@DRIVER_NAME@_drv.la: $(@DRIVER_NAME@_drv_la_OBJECTS) $(@DRIVER_NAME@_drv_la_DEPENDENCIES) $(EXTRA_@DRIVER_NAME@_drv_la_DEPENDENCIES)
+ $(AM_V_CCLD)$(@DRIVER_NAME@_drv_la_LINK) -rpath $(@DRIVER_NAME@_drv_ladir) $(@DRIVER_NAME@_drv_la_OBJECTS) $(@DRIVER_NAME@_drv_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/@DRIVER_NAME@.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apple.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/draglock.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/emuMB.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/emuThird.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/emuWheel.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ set x; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+ for dir in "$(DESTDIR)$(@DRIVER_NAME@_drv_ladir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-@DRIVER_NAME@_drv_laLTLIBRARIES clean-generic \
+ clean-libtool mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-@DRIVER_NAME@_drv_laLTLIBRARIES
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-@DRIVER_NAME@_drv_laLTLIBRARIES
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean \
+ clean-@DRIVER_NAME@_drv_laLTLIBRARIES clean-generic \
+ clean-libtool ctags distclean distclean-compile \
+ distclean-generic distclean-libtool distclean-tags distdir dvi \
+ dvi-am html html-am info info-am install \
+ install-@DRIVER_NAME@_drv_laLTLIBRARIES install-am \
+ install-data install-data-am install-dvi install-dvi-am \
+ install-exec install-exec-am install-html install-html-am \
+ install-info install-info-am install-man install-pdf \
+ install-pdf-am install-ps install-ps-am install-strip \
+ installcheck installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-@DRIVER_NAME@_drv_laLTLIBRARIES \
+ uninstall-am
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/apple.c b/src/apple.c
new file mode 100644
index 0000000..8e00a84
--- /dev/null
+++ b/src/apple.c
@@ -0,0 +1,312 @@
+/*
+ * Copyright © 2011 Red Hat, Inc.
+ *
+ * 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 Red Hat
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission. Red
+ * Hat makes 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.
+ *
+ * Authors:
+ * Peter Hutterer (peter.hutterer@redhat.com)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <evdev.h>
+#include <evdev-properties.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <exevents.h>
+#include <xf86.h>
+#include <xf86Xinput.h>
+#include <X11/Xatom.h>
+
+/* Apple-specific controls.
+ *
+ * On Apple keyboards, the multimedia function keys are overlaid with the F
+ * keys. F1 is also BrightnessDown, F10 is Mute, etc. The kernel provides a
+ * tweak to enable/disable this.
+ *
+ * /sys/module/hid_apple/parameters/fnmode
+ * 0 .. keyboard sends Fx keys, fn is disabled
+ * 1 .. keyboard sends multimedia keys, fn sends Fx keys
+ * 2 .. keyboard sends Fx keys, fn sends multimedia keys
+ *
+ * We only handle 1 and 2, don't care about 0. If fnmode is found to be on
+ * 0, we force it to 2 instead.
+ */
+
+/* In this file: fkeymode refers to the evdev-specific enums and parameters,
+ * fnmode refers to the fnmode parameter exposed by the kernel. fnmode is
+ * apple-specific */
+#define FNMODE_PATH "/sys/module/hid_apple/parameters/fnmode"
+
+/* Taken from the kernel */
+#define USB_VENDOR_ID_APPLE 0x05ac
+#define USB_DEVICE_ID_APPLE_ALU_MINI_ANSI 0x021d
+#define USB_DEVICE_ID_APPLE_ALU_MINI_ISO 0x021e
+#define USB_DEVICE_ID_APPLE_ALU_MINI_JIS 0x021f
+#define USB_DEVICE_ID_APPLE_ALU_ANSI 0x0220
+#define USB_DEVICE_ID_APPLE_ALU_ISO 0x0221
+#define USB_DEVICE_ID_APPLE_ALU_JIS 0x0222
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI 0x022c
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO 0x022d
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS 0x022e
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI 0x0239
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO 0x023a
+#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b
+
+static int EvdevAppleGetProperty (DeviceIntPtr dev, Atom property);
+static int EvdevAppleSetProperty(DeviceIntPtr dev, Atom atom,
+ XIPropertyValuePtr val, BOOL checkonly);
+
+static Atom prop_fkeymode;
+static Bool fnmode_readonly; /* set if we can only read fnmode */
+
+struct product_table
+{
+ unsigned int vendor;
+ unsigned int product;
+} apple_keyboard_table[] = {
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI},
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO},
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS},
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI},
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO},
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS},
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI},
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO},
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS},
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI},
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO},
+ { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS},
+ { 0, 0}
+};
+
+/**
+ * @return TRUE if the device matches a product in the given product table,
+ * FALSE otherwise
+ */
+static Bool product_check(const struct product_table *t, int vendor, int product)
+{
+ while (t->vendor)
+ {
+ if (vendor == t->vendor && product == t->product)
+ return TRUE;
+ t++;
+ }
+
+ return FALSE;
+}
+
+/**
+ * @return 0 on success, -1 otherwise (check errno)
+ */
+static int
+set_fnmode(enum fkeymode fkeymode)
+{
+ int fd;
+ char mode;
+ int bytes_written;
+
+ if (fkeymode == FKEYMODE_UNKNOWN)
+ {
+ errno = EINVAL; /* silly you */
+ return -1;
+ }
+
+ fd = open(FNMODE_PATH, O_WRONLY);
+ if (fd < 0)
+ return -1;
+
+ mode = (fkeymode == FKEYMODE_FKEYS) ? '2' : '1';
+
+ bytes_written = write(fd, &mode, 1);
+ close(fd);
+
+ return (bytes_written == 1) ? 0 : -1;
+}
+
+/**
+ * Get the current value of fnmode. If fnmode is found to be on 0, we set it
+ * to 2 in the process. Yes, quite daring, I know. I live on the edge.
+ *
+ * @return The current setting of fnmode or FKEYMODE_UNKNOWN on error (check
+ * errno)
+ */
+static enum fkeymode
+get_fnmode(void)
+{
+ int fd;
+ char retvalue;
+
+ fd = open(FNMODE_PATH, O_RDWR);
+ if (fd < 0 && errno == EACCES)
+ {
+ fnmode_readonly = TRUE;
+ fd = open(FNMODE_PATH, O_RDONLY);
+ }
+
+ if (fd < 0)
+ goto err;
+
+ if (read(fd, &retvalue, 1) != 1)
+ goto err;
+
+ if (retvalue != '0' && retvalue != '1' && retvalue != '2')
+ {
+ xf86Msg(X_ERROR, "Invalid fnmode value: %c\n", retvalue);
+ errno = EINVAL;
+ goto err;
+ }
+
+ close(fd);
+
+ /* we don't want 0, switch to 2 */
+ if (retvalue == '0')
+ {
+ if (fnmode_readonly)
+ xf86Msg(X_WARNING, "fnmode is disabled and read-only. Fn key will"
+ "not toggle to multimedia keys.\n");
+ else
+ set_fnmode(FKEYMODE_FKEYS);
+ }
+
+
+ return retvalue == '1' ? FKEYMODE_MMKEYS : FKEYMODE_FKEYS;
+
+err:
+ if (fd >= 0)
+ close(fd);
+ return FKEYMODE_UNKNOWN;
+}
+
+/**
+ * Set the property value to fkeymode. If the property doesn't exist,
+ * initialize it.
+ */
+static void set_fkeymode_property(InputInfoPtr pInfo, enum fkeymode fkeymode)
+{
+ DeviceIntPtr dev = pInfo->dev;
+ BOOL init = FALSE;
+ char data;
+
+ switch(fkeymode)
+ {
+ case FKEYMODE_FKEYS: data = 0; break;
+ case FKEYMODE_MMKEYS: data = 1; break;
+ case FKEYMODE_UNKNOWN:
+ xf86IDrvMsg(pInfo, X_ERROR, "Failed to get fnmode (%s)\n", strerror(errno));
+ return;
+ }
+
+ if (!prop_fkeymode) {
+ init = TRUE;
+ prop_fkeymode = MakeAtom(EVDEV_PROP_FUNCTION_KEYS, strlen(EVDEV_PROP_FUNCTION_KEYS), TRUE);
+ }
+
+ /* Don't send an event if we're initializing the property */
+ XIChangeDeviceProperty(dev, prop_fkeymode, XA_INTEGER, 8,
+ PropModeReplace, 1, &data, !init);
+
+ if (init)
+ {
+ XISetDevicePropertyDeletable(dev, prop_fkeymode, FALSE);
+ XIRegisterPropertyHandler(dev, EvdevAppleSetProperty, EvdevAppleGetProperty, NULL);
+ }
+}
+
+
+/**
+ * Called when a client reads the property state.
+ * Update with current kernel state, it may have changed behind our back.
+ */
+static int
+EvdevAppleGetProperty (DeviceIntPtr dev, Atom property)
+{
+ if (property == prop_fkeymode)
+ {
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+ enum fkeymode fkeymode;
+
+ fkeymode = get_fnmode();
+ if (fkeymode != pEvdev->fkeymode) {
+ /* set internal copy first, so we don't write to the file in
+ * SetProperty handler */
+ pEvdev->fkeymode = fkeymode;
+ set_fkeymode_property(pInfo, fkeymode);
+ }
+ }
+ return Success;
+}
+
+static int
+EvdevAppleSetProperty(DeviceIntPtr dev, Atom atom,
+ XIPropertyValuePtr val, BOOL checkonly)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (atom == prop_fkeymode)
+ {
+ CARD8 v = *(CARD8*)val->data;
+
+ if (val->format != 8 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ if (fnmode_readonly)
+ return BadAccess;
+
+ if (v > 1)
+ return BadValue;
+
+ if (!checkonly)
+ {
+ if ((!v && pEvdev->fkeymode != FKEYMODE_FKEYS) ||
+ (v && pEvdev->fkeymode != FKEYMODE_MMKEYS))
+ {
+ pEvdev->fkeymode = v ? FKEYMODE_MMKEYS : FKEYMODE_FKEYS;
+ set_fnmode(pEvdev->fkeymode);
+ }
+ }
+ }
+
+ return Success;
+}
+
+void
+EvdevAppleInitProperty(DeviceIntPtr dev)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+ enum fkeymode fkeymode;
+
+ if (!product_check(apple_keyboard_table,
+ pEvdev->id_vendor, pEvdev->id_product))
+ return;
+
+ fkeymode = get_fnmode();
+ pEvdev->fkeymode = fkeymode;
+ set_fkeymode_property(pInfo, fkeymode);
+}
diff --git a/src/draglock.c b/src/draglock.c
new file mode 100644
index 0000000..ac9d9c0
--- /dev/null
+++ b/src/draglock.c
@@ -0,0 +1,318 @@
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ * 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
+ * Copyright 2008 by Chris Salch
+ * Copyright 2008 Red Hat, Inc.
+ *
+ * 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.
+ *
+ */
+
+/* Draglock code */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "evdev.h"
+
+#include <xf86.h>
+#include <xf86Xinput.h>
+#include <X11/Xatom.h>
+#include <exevents.h>
+
+#include <evdev-properties.h>
+
+static Atom prop_dlock = 0; /* Drag lock buttons. */
+
+void EvdevDragLockLockButton(InputInfoPtr pInfo, unsigned int button);
+
+
+/* Setup and configuration code */
+void
+EvdevDragLockPreInit(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
+ char *option_string = NULL;
+ int meta_button = 0;
+ int lock_button = 0;
+ char *next_num = NULL;
+ char *end_str = NULL;
+ BOOL pairs = FALSE;
+
+ option_string = xf86CheckStrOption(pInfo->options, "DragLockButtons",NULL);
+
+ if (!option_string)
+ return;
+
+ next_num = option_string;
+
+ /* Loop until we hit the end of our option string */
+ while (next_num != NULL) {
+ lock_button = 0;
+ meta_button = strtol(next_num, &end_str, 10);
+
+ /* check to see if we found anything */
+ if (next_num != end_str) {
+ /* setup for the next number */
+ next_num = end_str;
+ } else {
+ /* we have nothing more to parse, drop out of the loop */
+ next_num = NULL;
+ }
+
+ /* Check for a button to lock if we have a meta button */
+ if (meta_button != 0 && next_num != NULL ) {
+ lock_button = strtol(next_num, &end_str, 10);
+
+ /* check to see if we found anything */
+ if (next_num != end_str) {
+ /* setup for the next number */
+ next_num = end_str;
+ } else {
+ /* we have nothing more to parse, drop out of the loop */
+ next_num = NULL;
+ }
+ }
+
+ /* Ok, let the user know what we found on this look */
+ if (meta_button != 0) {
+ if (lock_button == 0) {
+ if (!pairs) {
+ /* We only have a meta button */
+ pEvdev->dragLock.meta = meta_button;
+
+ xf86IDrvMsg(pInfo, X_CONFIG, "DragLockButtons : "
+ "%i as meta\n", meta_button);
+ } else {
+ xf86IDrvMsg(pInfo, X_ERROR, "DragLockButtons : "
+ "Incomplete pair specifying button pairs %s\n",
+ option_string);
+ }
+ } else {
+
+ /* Do bounds checking to make sure we don't crash */
+ if ((meta_button <= EVDEV_MAXBUTTONS) && (meta_button >= 0 ) &&
+ (lock_button <= EVDEV_MAXBUTTONS) && (lock_button >= 0)) {
+
+ xf86IDrvMsg(pInfo, X_CONFIG,
+ "DragLockButtons : %i -> %i\n",
+ meta_button, lock_button);
+
+ pEvdev->dragLock.lock_pair[meta_button - 1] = lock_button;
+ pairs=TRUE;
+ } else {
+ /* Let the user know something was wrong
+ with this pair of buttons */
+ xf86IDrvMsg(pInfo, X_CONFIG,"DragLockButtons : "
+ "Invalid button pair %i -> %i\n",
+ meta_button, lock_button);
+ }
+ }
+ } else {
+ xf86IDrvMsg(pInfo, X_ERROR, "Found DragLockButtons "
+ "with invalid lock button string : '%s'\n",
+ option_string);
+
+ /* This should be the case anyhow, just make sure */
+ next_num = NULL;
+ }
+
+ /* Check for end of string, to avoid annoying error */
+ if (next_num != NULL && *next_num == '\0')
+ next_num = NULL;
+ }
+
+ free(option_string);
+}
+
+/* Updates DragLock button state and fires button event messges */
+void
+EvdevDragLockLockButton(InputInfoPtr pInfo, unsigned int button)
+{
+ EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
+ BOOL state = 0;
+
+ /* update button state */
+ state = pEvdev->dragLock.lock_state[button - 1] ? FALSE : TRUE;
+ pEvdev->dragLock.lock_state[button - 1] = state;
+
+ EvdevQueueButtonEvent(pInfo, button, state);
+}
+
+/* Filter button presses looking for either a meta button or the
+ * control of a button pair.
+ *
+ * @param button button number (1 for left, 3 for right)
+ * @param value TRUE if button press, FALSE if release
+ *
+ * @return TRUE if the event was swallowed here, FALSE otherwise.
+ */
+BOOL
+EvdevDragLockFilterEvent(InputInfoPtr pInfo, unsigned int button, int value)
+{
+ EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
+
+ if (button == 0)
+ return FALSE;
+
+ /* Do we have a single meta key or
+ several button pairings? */
+ if (pEvdev->dragLock.meta != 0) {
+
+ if (pEvdev->dragLock.meta == button) {
+
+ /* setup up for button lock */
+ if (value)
+ pEvdev->dragLock.meta_state = TRUE;
+
+ return TRUE;
+ } else if (pEvdev->dragLock.meta_state) { /* waiting to lock */
+
+ pEvdev->dragLock.meta_state = FALSE;
+
+ EvdevDragLockLockButton(pInfo, button);
+
+ return TRUE;
+ }
+ } else if (pEvdev->dragLock.lock_pair[button - 1] && value) {
+ /* A meta button in a meta/lock pair was pressed */
+ EvdevDragLockLockButton(pInfo, pEvdev->dragLock.lock_pair[button - 1]);
+ return TRUE;
+ }
+
+ /* Eat events for buttons that are locked */
+ if (pEvdev->dragLock.lock_state[button - 1])
+ return TRUE;
+
+ return FALSE;
+}
+
+/**
+ * Set the drag lock property.
+ * If only one value is supplied, then this is used as the meta button.
+ * If more than one value is supplied, then each value is the drag lock button
+ * for the pair. 0 disables a pair.
+ * i.e. to set bt 3 to draglock button 1, supply 0,0,1
+ */
+static int
+EvdevDragLockSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
+ BOOL checkonly)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (atom == prop_dlock)
+ {
+ int i;
+
+ if (val->format != 8 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ /* Don't allow changes while a lock is active */
+ if (pEvdev->dragLock.meta)
+ {
+ if (pEvdev->dragLock.meta_state)
+ return BadAccess;
+ } else
+ {
+ for (i = 0; i < EVDEV_MAXBUTTONS; i++)
+ if (pEvdev->dragLock.lock_state[i])
+ return BadValue;
+ }
+
+ if (val->size == 0)
+ return BadMatch;
+ else if (val->size == 1)
+ {
+ int meta = *((CARD8*)val->data);
+ if (meta > EVDEV_MAXBUTTONS)
+ return BadValue;
+
+ if (!checkonly)
+ {
+ pEvdev->dragLock.meta = meta;
+ memset(pEvdev->dragLock.lock_pair, 0, sizeof(pEvdev->dragLock.lock_pair));
+ }
+ } else if ((val->size % 2) == 0)
+ {
+ CARD8* vals = (CARD8*)val->data;
+
+ for (i = 0; i < val->size && i < EVDEV_MAXBUTTONS; i++)
+ if (vals[i] > EVDEV_MAXBUTTONS)
+ return BadValue;
+
+ if (!checkonly)
+ {
+ pEvdev->dragLock.meta = 0;
+ memset(pEvdev->dragLock.lock_pair, 0, sizeof(pEvdev->dragLock.lock_pair));
+
+ for (i = 0; i < val->size && i < EVDEV_MAXBUTTONS; i += 2)
+ pEvdev->dragLock.lock_pair[vals[i] - 1] = vals[i + 1];
+ }
+ } else
+ return BadMatch;
+ }
+
+ return Success;
+}
+
+/**
+ * Initialise property for drag lock buttons setting.
+ */
+void
+EvdevDragLockInitProperty(DeviceIntPtr dev)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (!dev->button) /* don't init prop for keyboards */
+ return;
+
+ prop_dlock = MakeAtom(EVDEV_PROP_DRAGLOCK, strlen(EVDEV_PROP_DRAGLOCK), TRUE);
+ if (pEvdev->dragLock.meta)
+ {
+ XIChangeDeviceProperty(dev, prop_dlock, XA_INTEGER, 8,
+ PropModeReplace, 1, &pEvdev->dragLock.meta,
+ FALSE);
+ } else {
+ int highest = 0;
+ int i;
+ CARD8 pair[EVDEV_MAXBUTTONS] = {0};
+
+ for (i = 0; i < EVDEV_MAXBUTTONS; i++)
+ {
+ if (pEvdev->dragLock.lock_pair[i])
+ highest = i;
+ pair[i] = pEvdev->dragLock.lock_pair[i];
+ }
+
+ XIChangeDeviceProperty(dev, prop_dlock, XA_INTEGER, 8, PropModeReplace,
+ highest + 1, pair, FALSE);
+ }
+
+ XISetDevicePropertyDeletable(dev, prop_dlock, FALSE);
+
+ XIRegisterPropertyHandler(dev, EvdevDragLockSetProperty, NULL, NULL);
+}
diff --git a/src/emuMB.c b/src/emuMB.c
new file mode 100644
index 0000000..eb01495
--- /dev/null
+++ b/src/emuMB.c
@@ -0,0 +1,391 @@
+/*
+ * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+ * Copyright 1993 by David Dawes <dawes@xfree86.org>
+ * 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.
+ *
+ */
+
+/* Middle mouse button emulation code. */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "evdev.h"
+
+#include <X11/Xatom.h>
+#include <xf86.h>
+#include <xf86Xinput.h>
+#include <exevents.h>
+
+#include <evdev-properties.h>
+
+static Atom prop_mbemu = 0; /* Middle button emulation on/off property */
+static Atom prop_mbtimeout = 0; /* Middle button timeout property */
+/*
+ * 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
+ * <button state> (<events>) -> <new emulation state>
+ * which should be read as
+ * If the buttons are in <button state>, generate <events> then go to
+ * <new emulation state>.
+ */
+static signed char stateTab[11][5][3] = {
+/* 0 ground */
+ {
+ { 0, 0, 0 }, /* nothing -> ground (no change) */
+ { 0, 0, 1 }, /* left -> delayed left */
+ { 0, 0, 2 }, /* right -> delayed right */
+ { 2, 0, 3 }, /* left & right (middle press) -> pressed middle */
+ { 0, 0, -1 } /* timeout N/A */
+ },
+/* 1 delayed left */
+ {
+ { 1, -1, 0 }, /* nothing (left event) -> ground */
+ { 0, 0, 1 }, /* left -> delayed left (no change) */
+ { 1, -1, 2 }, /* right (left event) -> delayed right */
+ { 2, 0, 3 }, /* left & right (middle press) -> pressed middle */
+ { 1, 0, 4 }, /* timeout (left press) -> pressed left */
+ },
+/* 2 delayed right */
+ {
+ { 3, -3, 0 }, /* nothing (right event) -> ground */
+ { 3, -3, 1 }, /* left (right event) -> delayed left (no change) */
+ { 0, 0, 2 }, /* right -> delayed right (no change) */
+ { 2, 0, 3 }, /* left & right (middle press) -> pressed middle */
+ { 3, 0, 5 }, /* timeout (right press) -> pressed right */
+ },
+/* 3 pressed middle */
+ {
+ { -2, 0, 0 }, /* nothing (middle release) -> ground */
+ { 0, 0, 7 }, /* left -> released right */
+ { 0, 0, 6 }, /* right -> released left */
+ { 0, 0, 3 }, /* left & right -> pressed middle (no change) */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 4 pressed left */
+ {
+ { -1, 0, 0 }, /* nothing (left release) -> ground */
+ { 0, 0, 4 }, /* left -> pressed left (no change) */
+ { -1, 0, 2 }, /* right (left release) -> delayed right */
+ { 3, 0, 10 }, /* left & right (right press) -> pressed both */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 5 pressed right */
+ {
+ { -3, 0, 0 }, /* nothing (right release) -> ground */
+ { -3, 0, 1 }, /* left (right release) -> delayed left */
+ { 0, 0, 5 }, /* right -> pressed right (no change) */
+ { 1, 0, 10 }, /* left & right (left press) -> pressed both */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 6 released left */
+ {
+ { -2, 0, 0 }, /* nothing (middle release) -> ground */
+ { -2, 0, 1 }, /* left (middle release) -> delayed left */
+ { 0, 0, 6 }, /* right -> released left (no change) */
+ { 1, 0, 8 }, /* left & right (left press) -> repressed left */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 7 released right */
+ {
+ { -2, 0, 0 }, /* nothing (middle release) -> ground */
+ { 0, 0, 7 }, /* left -> released right (no change) */
+ { -2, 0, 2 }, /* right (middle release) -> delayed right */
+ { 3, 0, 9 }, /* left & right (right press) -> repressed right */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 8 repressed left */
+ {
+ { -2, -1, 0 }, /* nothing (middle release, left release) -> ground */
+ { -2, 0, 4 }, /* left (middle release) -> pressed left */
+ { -1, 0, 6 }, /* right (left release) -> released left */
+ { 0, 0, 8 }, /* left & right -> repressed left (no change) */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 9 repressed right */
+ {
+ { -2, -3, 0 }, /* nothing (middle release, right release) -> ground */
+ { -3, 0, 7 }, /* left (right release) -> released right */
+ { -2, 0, 5 }, /* right (middle release) -> pressed right */
+ { 0, 0, 9 }, /* left & right -> repressed right (no change) */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+/* 10 pressed both */
+ {
+ { -1, -3, 0 }, /* nothing (left release, right release) -> ground */
+ { -3, 0, 4 }, /* left (right release) -> pressed left */
+ { -1, 0, 5 }, /* right (left release) -> pressed right */
+ { 0, 0, 10 }, /* left & right -> pressed both (no change) */
+ { 0, 0, -1 }, /* timeout N/A */
+ },
+};
+
+
+int
+EvdevMBEmuTimer(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ int sigstate;
+ int id;
+
+ sigstate = xf86BlockSIGIO ();
+
+ pEvdev->emulateMB.pending = FALSE;
+ if ((id = stateTab[pEvdev->emulateMB.state][4][0]) != 0) {
+ EvdevPostButtonEvent(pInfo, abs(id),
+ (id >= 0) ? BUTTON_PRESS : BUTTON_RELEASE);
+ pEvdev->emulateMB.state =
+ stateTab[pEvdev->emulateMB.state][4][2];
+ } else {
+ ErrorF("Got unexpected buttonTimer in state %d\n",
+ pEvdev->emulateMB.state);
+ }
+
+ xf86UnblockSIGIO (sigstate);
+ return 0;
+}
+
+
+/**
+ * Emulate a middle button on button press.
+ *
+ * @param code button number (1 for left, 3 for right)
+ * @param press TRUE if press, FALSE if release.
+ *
+ * @return TRUE if event was swallowed by middle mouse button emulation, FALSE
+ * otherwise.
+ */
+BOOL
+EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ int id;
+ int *btstate;
+ int ret = FALSE;
+
+ if (!pEvdev->emulateMB.enabled)
+ return ret;
+
+ /* don't care about other buttons */
+ if (button != 1 && button != 3)
+ return ret;
+
+ btstate = &pEvdev->emulateMB.buttonstate;
+ if (press)
+ *btstate |= (button == 1) ? 0x1 : 0x2;
+ else
+ *btstate &= (button == 1) ? ~0x1 : ~0x2;
+
+ if ((id = stateTab[pEvdev->emulateMB.state][*btstate][0]) != 0)
+ {
+ EvdevQueueButtonEvent(pInfo, abs(id), (id >= 0));
+ ret = TRUE;
+ }
+ if ((id = stateTab[pEvdev->emulateMB.state][*btstate][1]) != 0)
+ {
+ EvdevQueueButtonEvent(pInfo, abs(id), (id >= 0));
+ ret = TRUE;
+ }
+
+ pEvdev->emulateMB.state =
+ stateTab[pEvdev->emulateMB.state][*btstate][2];
+
+ if (stateTab[pEvdev->emulateMB.state][4][0] != 0) {
+ pEvdev->emulateMB.expires = GetTimeInMillis () + pEvdev->emulateMB.timeout;
+ pEvdev->emulateMB.pending = TRUE;
+ ret = TRUE;
+ } else {
+ pEvdev->emulateMB.pending = FALSE;
+ }
+
+ return ret;
+}
+
+
+void EvdevMBEmuWakeupHandler(pointer data,
+ int i,
+ pointer LastSelectMask)
+{
+ InputInfoPtr pInfo = (InputInfoPtr)data;
+ EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
+ int ms;
+
+ if (pEvdev->emulateMB.pending)
+ {
+ ms = pEvdev->emulateMB.expires - GetTimeInMillis();
+ if (ms <= 0)
+ EvdevMBEmuTimer(pInfo);
+ }
+}
+
+void EvdevMBEmuBlockHandler(pointer data,
+ struct timeval **waitTime,
+ pointer LastSelectMask)
+{
+ InputInfoPtr pInfo = (InputInfoPtr) data;
+ EvdevPtr pEvdev= (EvdevPtr) pInfo->private;
+ int ms;
+
+ if (pEvdev->emulateMB.pending)
+ {
+ ms = pEvdev->emulateMB.expires - GetTimeInMillis ();
+ if (ms <= 0)
+ ms = 0;
+ AdjustWaitForDelay (waitTime, ms);
+ }
+}
+
+void
+EvdevMBEmuPreInit(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
+
+ pEvdev->emulateMB.enabled = xf86SetBoolOption(pInfo->options,
+ "Emulate3Buttons",
+ FALSE);
+ pEvdev->emulateMB.timeout = xf86SetIntOption(pInfo->options,
+ "Emulate3Timeout", 50);
+}
+
+void
+EvdevMBEmuOn(InputInfoPtr pInfo)
+{
+ if (!pInfo->dev->button) /* don't init for keyboards */
+ return;
+
+ RegisterBlockAndWakeupHandlers (EvdevMBEmuBlockHandler,
+ EvdevMBEmuWakeupHandler,
+ (pointer)pInfo);
+}
+
+void
+EvdevMBEmuFinalize(InputInfoPtr pInfo)
+{
+ if (!pInfo->dev->button) /* don't cleanup for keyboards */
+ return;
+
+ RemoveBlockAndWakeupHandlers (EvdevMBEmuBlockHandler,
+ EvdevMBEmuWakeupHandler,
+ (pointer)pInfo);
+
+}
+
+static int
+EvdevMBEmuSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
+ BOOL checkonly)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (atom == prop_mbemu)
+ {
+ if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ if (!checkonly)
+ pEvdev->emulateMB.enabled = *((BOOL*)val->data);
+ } else if (atom == prop_mbtimeout)
+ {
+ if (val->format != 32 || val->size != 1 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ if (!checkonly)
+ pEvdev->emulateMB.timeout = *((CARD32*)val->data);
+ }
+
+ return Success;
+}
+
+/**
+ * Initialise property for MB emulation on/off.
+ */
+void
+EvdevMBEmuInitProperty(DeviceIntPtr dev)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+ int rc;
+
+ if (!dev->button) /* don't init prop for keyboards */
+ return;
+
+ prop_mbemu = MakeAtom(EVDEV_PROP_MIDBUTTON, strlen(EVDEV_PROP_MIDBUTTON), TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_mbemu, XA_INTEGER, 8,
+ PropModeReplace, 1,
+ &pEvdev->emulateMB.enabled,
+ FALSE);
+ if (rc != Success)
+ return;
+ XISetDevicePropertyDeletable(dev, prop_mbemu, FALSE);
+
+ prop_mbtimeout = MakeAtom(EVDEV_PROP_MIDBUTTON_TIMEOUT,
+ strlen(EVDEV_PROP_MIDBUTTON_TIMEOUT),
+ TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_mbtimeout, XA_INTEGER, 32, PropModeReplace, 1,
+ &pEvdev->emulateMB.timeout, FALSE);
+
+ if (rc != Success)
+ return;
+ XISetDevicePropertyDeletable(dev, prop_mbtimeout, FALSE);
+
+ XIRegisterPropertyHandler(dev, EvdevMBEmuSetProperty, NULL, NULL);
+}
diff --git a/src/emuThird.c b/src/emuThird.c
new file mode 100644
index 0000000..7461767
--- /dev/null
+++ b/src/emuThird.c
@@ -0,0 +1,416 @@
+/*
+ * Copyright © 2011 Red Hat, Inc.
+ *
+ * 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.
+ *
+ */
+
+/* Right mouse button emulation code.
+ * Emulates a right button event if the first button is held down for a
+ * timeout. If the device moves more than a certain amount before the
+ * timeout is over, the emulation is cancelled and a normal button event is
+ * generated.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "evdev.h"
+
+#include <X11/Xatom.h>
+#include <xf86.h>
+#include <xf86Xinput.h>
+#include <exevents.h>
+
+#include <evdev-properties.h>
+
+/* Threshold (in device coordinates) for devices to cancel emulation */
+#define DEFAULT_MOVE_THRESHOLD 20
+
+static Atom prop_3bemu; /* Right button emulation on/off property */
+static Atom prop_3btimeout; /* Right button timeout property */
+static Atom prop_3bbutton; /* Right button target physical button */
+static Atom prop_3bthreshold; /* Right button move cancellation threshold */
+
+/* State machine for 3rd button emulation */
+enum EmulationState {
+ EM3B_OFF, /* no event */
+ EM3B_PENDING, /* timer pending */
+ EM3B_EMULATING /* in emulation */
+};
+
+static void
+Evdev3BEmuPostButtonEvent(InputInfoPtr pInfo, int button, enum ButtonAction act)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ struct emulate3B *emu3B = &pEvdev->emulate3B;
+ int absolute = Relative;
+
+ /* if we cancel, emit the button down event at our start position,
+ * not at the current position. Only for absolute devices though. For
+ * relative events, this may be a bit iffy since pointer accel may shoot
+ * us back more than we moved and confuse the user.
+ */
+ if (emu3B->flags & EVDEV_ABSOLUTE_EVENTS)
+ absolute = Absolute;
+
+ xf86PostButtonEventP(pInfo->dev, absolute, button,
+ (act == BUTTON_PRESS) ? 1 : 0, 0,
+ (absolute ? 2 : 0), emu3B->startpos);
+}
+
+
+/**
+ * Timer function. Post a button down event to the server.
+ *
+ * @param arg The InputInfoPtr for this device.
+ */
+CARD32
+Evdev3BEmuTimer(OsTimerPtr timer, CARD32 time, pointer arg)
+{
+ InputInfoPtr pInfo = (InputInfoPtr)arg;
+ EvdevPtr pEvdev = pInfo->private;
+ struct emulate3B *emu3B = &pEvdev->emulate3B;
+ int sigstate = 0;
+
+ sigstate = xf86BlockSIGIO ();
+ emu3B->state = EM3B_EMULATING;
+ Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, BUTTON_PRESS);
+ xf86UnblockSIGIO (sigstate);
+ return 0;
+}
+
+
+/**
+ * Cancel all emulation, reset the timer and reset deltas.
+ */
+static void
+Evdev3BCancel(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ struct emulate3B *emu3B = &pEvdev->emulate3B;
+
+ if (emu3B->state != EM3B_OFF)
+ {
+ TimerCancel(emu3B->timer);
+ emu3B->state = EM3B_OFF;
+ memset(emu3B->delta, 0, sizeof(emu3B->delta));
+ }
+
+ emu3B->flags = 0;
+}
+
+/**
+ * Emulate a third button on button press. Note that emulation only triggers
+ * on button 1.
+ *
+ * Return TRUE if event was swallowed by middle mouse button emulation,
+ * FALSE otherwise.
+ */
+BOOL
+Evdev3BEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ struct emulate3B *emu3B = &pEvdev->emulate3B;
+ int ret = FALSE;
+
+ if (!emu3B->enabled)
+ goto out;
+
+ if (press)
+ emu3B->buttonstate |= button;
+ else
+ emu3B->buttonstate &= ~button;
+
+ /* Any other button pressed? Cancel timer */
+ if (button != 1)
+ {
+ switch (emu3B->state)
+ {
+ case EM3B_PENDING:
+ Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS);
+ Evdev3BCancel(pInfo);
+ break;
+ case EM3B_EMULATING:
+ /* We're emulating and now the user pressed a different
+ * button. Just release the emulating one, tell the user to
+ * not do that and get on with life */
+ Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, BUTTON_RELEASE);
+ Evdev3BCancel(pInfo);
+ break;
+ default:
+ break;
+ }
+ goto out;
+ }
+
+ /* Don't emulate if any other button is down */
+ if ((emu3B->buttonstate & ~0x1) != 0)
+ goto out;
+
+ /* Release event → cancel, send press and release now. */
+ if (!press)
+ {
+ switch(emu3B->state)
+ {
+ case EM3B_PENDING:
+ Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS);
+ Evdev3BCancel(pInfo);
+ break;
+ case EM3B_EMULATING:
+ Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, BUTTON_RELEASE);
+ Evdev3BCancel(pInfo);
+ ret = TRUE;
+ break;
+ default:
+ break;
+ }
+
+ goto out;
+ }
+
+ if (press && emu3B->state == EM3B_OFF)
+ {
+ emu3B->state = EM3B_PENDING;
+ emu3B->timer = TimerSet(emu3B->timer, 0, emu3B->timeout,
+ Evdev3BEmuTimer, pInfo);
+ ret = TRUE;
+ goto out;
+ }
+
+out:
+ return ret;
+}
+
+/**
+ * Handle absolute x/y motion. If the motion is above the threshold, cancel
+ * emulation.
+ */
+void
+Evdev3BEmuProcessAbsMotion(InputInfoPtr pInfo, ValuatorMask *vals)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ struct emulate3B *emu3B = &pEvdev->emulate3B;
+ int cancel = FALSE;
+ int axis = 0;
+
+ if (emu3B->state != EM3B_PENDING)
+ {
+ if (valuator_mask_isset(vals, 0))
+ emu3B->startpos[0] = valuator_mask_get(vals, 0);
+ if (valuator_mask_isset(vals, 1))
+ emu3B->startpos[1] = valuator_mask_get(vals, 1);
+
+ return;
+ }
+
+ if ((emu3B->flags & EVDEV_ABSOLUTE_EVENTS) == 0)
+ emu3B->flags |= EVDEV_ABSOLUTE_EVENTS;
+
+ while (axis <= 1 && !cancel)
+ {
+ if (valuator_mask_isset(vals, axis))
+ {
+ int delta = valuator_mask_get(vals, axis) - emu3B->startpos[axis];
+ if (abs(delta) > emu3B->threshold)
+ cancel = TRUE;
+ }
+ axis++;
+ }
+
+ if (cancel)
+ {
+ Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS);
+ Evdev3BCancel(pInfo);
+ }
+}
+
+/**
+ * Handle relative x/y motion. If the motion is above the threshold, cancel
+ * emulation.
+ */
+void
+Evdev3BEmuProcessRelMotion(InputInfoPtr pInfo, int dx, int dy)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ struct emulate3B *emu3B = &pEvdev->emulate3B;
+
+ if (emu3B->state != EM3B_PENDING)
+ return;
+
+ emu3B->delta[0] += dx;
+ emu3B->delta[1] += dy;
+ emu3B->flags |= EVDEV_RELATIVE_EVENTS;
+
+ if (abs(emu3B->delta[0]) > emu3B->threshold ||
+ abs(emu3B->delta[1]) > emu3B->threshold)
+ {
+ Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS);
+ Evdev3BCancel(pInfo);
+ }
+}
+
+void
+Evdev3BEmuPreInit(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ struct emulate3B *emu3B = &pEvdev->emulate3B;
+
+ emu3B->enabled = xf86SetBoolOption(pInfo->options,
+ "EmulateThirdButton",
+ FALSE);
+ emu3B->timeout = xf86SetIntOption(pInfo->options,
+ "EmulateThirdButtonTimeout",
+ 1000);
+ emu3B->button = xf86SetIntOption(pInfo->options,
+ "EmulateThirdButtonButton",
+ 3);
+ /* FIXME: this should be auto-configured based on axis ranges */
+ emu3B->threshold = xf86SetIntOption(pInfo->options,
+ "EmulateThirdButtonMoveThreshold",
+ DEFAULT_MOVE_THRESHOLD);
+ /* allocate now so we don't allocate in the signal handler */
+ emu3B->timer = TimerSet(NULL, 0, 0, NULL, NULL);
+}
+
+void
+Evdev3BEmuOn(InputInfoPtr pInfo)
+{
+ /* This function just exists for symmetry in evdev.c */
+}
+
+void
+Evdev3BEmuFinalize(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ struct emulate3B *emu3B = &pEvdev->emulate3B;
+
+ TimerFree(emu3B->timer);
+ emu3B->timer = NULL;
+}
+
+static int
+Evdev3BEmuSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
+ BOOL checkonly)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+ struct emulate3B *emu3B = &pEvdev->emulate3B;
+
+ if (atom == prop_3bemu)
+ {
+ if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ if (!checkonly)
+ emu3B->enabled = *((BOOL*)val->data);
+
+ } else if (atom == prop_3btimeout)
+ {
+ if (val->format != 32 || val->size != 1 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ if (!checkonly)
+ emu3B->timeout = *((CARD32*)val->data);
+
+ } else if (atom == prop_3bbutton)
+ {
+ if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ if (!checkonly)
+ emu3B->button = *((CARD8*)val->data);
+ } else if (atom == prop_3bthreshold)
+ {
+ if (val->format != 32 || val->size != 1 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ if (!checkonly)
+ emu3B->threshold = *((CARD32*)val->data);
+ }
+
+
+ return Success;
+}
+
+/**
+ * Initialise properties for third button emulation
+ */
+void
+Evdev3BEmuInitProperty(DeviceIntPtr dev)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+ struct emulate3B *emu3B = &pEvdev->emulate3B;
+ int rc;
+
+ if (!dev->button) /* don't init prop for keyboards */
+ return;
+
+ /* third button emulation on/off */
+ prop_3bemu = MakeAtom(EVDEV_PROP_THIRDBUTTON, strlen(EVDEV_PROP_THIRDBUTTON), TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_3bemu, XA_INTEGER, 8,
+ PropModeReplace, 1,
+ &emu3B->enabled,
+ FALSE);
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_3bemu, FALSE);
+
+ /* third button emulation timeout */
+ prop_3btimeout = MakeAtom(EVDEV_PROP_THIRDBUTTON_TIMEOUT,
+ strlen(EVDEV_PROP_THIRDBUTTON_TIMEOUT),
+ TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_3btimeout, XA_INTEGER, 32, PropModeReplace, 1,
+ &emu3B->timeout, FALSE);
+
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_3btimeout, FALSE);
+
+ /* third button emulation button to be triggered */
+ prop_3bbutton = MakeAtom(EVDEV_PROP_THIRDBUTTON_BUTTON,
+ strlen(EVDEV_PROP_THIRDBUTTON_BUTTON),
+ TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_3bbutton, XA_INTEGER, 8, PropModeReplace, 1,
+ &emu3B->button, FALSE);
+
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_3bbutton, FALSE);
+
+ /* third button emulation movement threshold */
+ prop_3bthreshold = MakeAtom(EVDEV_PROP_THIRDBUTTON_THRESHOLD,
+ strlen(EVDEV_PROP_THIRDBUTTON_THRESHOLD),
+ TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_3bthreshold, XA_INTEGER, 32, PropModeReplace, 1,
+ &emu3B->threshold, FALSE);
+
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_3bthreshold, FALSE);
+
+ XIRegisterPropertyHandler(dev, Evdev3BEmuSetProperty, NULL, NULL);
+}
diff --git a/src/emuWheel.c b/src/emuWheel.c
new file mode 100644
index 0000000..db989c5
--- /dev/null
+++ b/src/emuWheel.c
@@ -0,0 +1,480 @@
+/*
+* Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
+* Copyright 1993 by David Dawes <dawes@xfree86.org>
+* 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 by Chris Salch
+* Copyright © 2008 Red Hat, Inc.
+*
+* 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.
+*
+*/
+
+/* Mouse wheel emulation code. */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "evdev.h"
+
+#include <X11/Xatom.h>
+#include <xf86.h>
+#include <xf86Xinput.h>
+#include <exevents.h>
+
+#include <evdev-properties.h>
+
+#define WHEEL_NOT_CONFIGURED 0
+
+static Atom prop_wheel_emu = 0;
+static Atom prop_wheel_axismap = 0;
+static Atom prop_wheel_inertia = 0;
+static Atom prop_wheel_timeout = 0;
+static Atom prop_wheel_button = 0;
+
+/* Local Funciton Prototypes */
+static int EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value);
+
+/* Filter mouse button events */
+BOOL
+EvdevWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value)
+{
+ EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
+ int ms;
+
+ /* Has wheel emulation been configured to be enabled? */
+ if (!pEvdev->emulateWheel.enabled)
+ return FALSE;
+
+ /* Check for EmulateWheelButton */
+ if (pEvdev->emulateWheel.button == button) {
+ pEvdev->emulateWheel.button_state = value;
+
+ if (value)
+ /* Start the timer when the button is pressed */
+ pEvdev->emulateWheel.expires = pEvdev->emulateWheel.timeout +
+ GetTimeInMillis();
+ else {
+ ms = pEvdev->emulateWheel.expires - GetTimeInMillis();
+ if (ms > 0) {
+ /*
+ * If the button is released early enough emit the button
+ * press/release events
+ */
+ EvdevQueueButtonClicks(pInfo, button, 1);
+ }
+ }
+
+ return TRUE;
+ }
+
+ /* Don't care about this event */
+ return FALSE;
+}
+
+/* Filter mouse wheel events */
+BOOL
+EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
+{
+ EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
+ WheelAxisPtr pAxis = NULL, pOtherAxis = NULL;
+ int value = pEv->value;
+ int oldValue;
+
+ /* Has wheel emulation been configured to be enabled? */
+ if (!pEvdev->emulateWheel.enabled)
+ return FALSE;
+
+ /* Handle our motion events if the emuWheel button is pressed
+ * wheel button of 0 means always emulate wheel.
+ */
+ if (pEvdev->emulateWheel.button_state || !pEvdev->emulateWheel.button) {
+ /* Just return if the timeout hasn't expired yet */
+ if (pEvdev->emulateWheel.button)
+ {
+ int ms = pEvdev->emulateWheel.expires - GetTimeInMillis();
+ if (ms > 0)
+ return TRUE;
+ }
+
+ /* We don't want to intercept real mouse wheel events */
+ if(pEv->type == EV_ABS) {
+ int axis = pEvdev->axis_map[pEv->code];
+ oldValue = valuator_mask_get(pEvdev->vals, axis);
+ valuator_mask_set(pEvdev->vals, axis, value);
+ value -= oldValue; /* make value into a differential measurement */
+ }
+
+ switch(pEv->code) {
+
+ /* ABS_X has the same value as REL_X, so this case catches both */
+ case REL_X:
+ pAxis = &(pEvdev->emulateWheel.X);
+ pOtherAxis = &(pEvdev->emulateWheel.Y);
+ break;
+
+ /* ABS_Y has the same value as REL_Y, so this case catches both */
+ case REL_Y:
+ pAxis = &(pEvdev->emulateWheel.Y);
+ pOtherAxis = &(pEvdev->emulateWheel.X);
+ break;
+
+ default:
+ break;
+ }
+
+ /* If we found REL_X, REL_Y, ABS_X or ABS_Y then emulate a mouse
+ wheel. Reset the inertia of the other axis when a scroll event
+ was sent to avoid the buildup of erroneous scroll events if the
+ user doesn't move in a perfectly straight line.
+ */
+ if (pAxis)
+ {
+ if (EvdevWheelEmuInertia(pInfo, pAxis, value))
+ pOtherAxis->traveled_distance = 0;
+ }
+
+ /* Eat motion events while emulateWheel button pressed. */
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/* Simulate inertia for our emulated mouse wheel.
+ Returns the number of wheel events generated.
+ */
+static int
+EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value)
+{
+ EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
+ int button;
+ int inertia;
+ int rc = 0;
+
+ /* if this axis has not been configured, just eat the motion */
+ if (!axis->up_button)
+ return rc;
+
+ axis->traveled_distance += value;
+
+ if (axis->traveled_distance < 0) {
+ button = axis->up_button;
+ inertia = -pEvdev->emulateWheel.inertia;
+ } else {
+ button = axis->down_button;
+ inertia = pEvdev->emulateWheel.inertia;
+ }
+
+ /* Produce button press events for wheel motion */
+ while(abs(axis->traveled_distance) > pEvdev->emulateWheel.inertia) {
+ axis->traveled_distance -= inertia;
+ EvdevQueueButtonClicks(pInfo, button, 1);
+ rc++;
+ }
+ return rc;
+}
+
+/* Handle button mapping here to avoid code duplication,
+returns true if a button mapping was found. */
+static BOOL
+EvdevWheelEmuHandleButtonMap(InputInfoPtr pInfo, WheelAxisPtr pAxis,
+ const char *axis_name)
+{
+ EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
+ char *option_string;
+
+ pAxis->up_button = WHEEL_NOT_CONFIGURED;
+
+ /* Check to see if there is configuration for this axis */
+ option_string = xf86SetStrOption(pInfo->options, axis_name, NULL);
+ if (option_string) {
+ int up_button = 0;
+ int down_button = 0;
+ char *msg = NULL;
+
+ if ((sscanf(option_string, "%d %d", &up_button, &down_button) == 2) &&
+ ((up_button > 0) && (up_button <= EVDEV_MAXBUTTONS)) &&
+ ((down_button > 0) && (down_button <= EVDEV_MAXBUTTONS))) {
+
+ /* Use xstrdup to allocate a string for us */
+ msg = xstrdup("buttons XX and YY");
+
+ if (msg)
+ sprintf(msg, "buttons %d and %d", up_button, down_button);
+
+ pAxis->up_button = up_button;
+ pAxis->down_button = down_button;
+
+ /* Update the number of buttons if needed */
+ if (up_button > pEvdev->num_buttons) pEvdev->num_buttons = up_button;
+ if (down_button > pEvdev->num_buttons) pEvdev->num_buttons = down_button;
+
+ } else {
+ xf86IDrvMsg(pInfo, X_WARNING, "Invalid %s value:\"%s\"\n",
+ axis_name, option_string);
+ }
+ free(option_string);
+
+ /* Clean up and log what happened */
+ if (msg) {
+ xf86IDrvMsg(pInfo, X_CONFIG, "%s: %s\n", axis_name, msg);
+ free(msg);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/* Setup the basic configuration options used by mouse wheel emulation */
+void
+EvdevWheelEmuPreInit(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
+ int wheelButton;
+ int inertia;
+ int timeout;
+
+ if (xf86SetBoolOption(pInfo->options, "EmulateWheel", FALSE)) {
+ pEvdev->emulateWheel.enabled = TRUE;
+ } else
+ pEvdev->emulateWheel.enabled = FALSE;
+
+ wheelButton = xf86SetIntOption(pInfo->options, "EmulateWheelButton", 4);
+
+ if ((wheelButton < 0) || (wheelButton > EVDEV_MAXBUTTONS)) {
+ xf86IDrvMsg(pInfo, X_WARNING, "Invalid EmulateWheelButton value: %d\n",
+ wheelButton);
+ xf86IDrvMsg(pInfo, X_WARNING, "Wheel emulation disabled.\n");
+
+ pEvdev->emulateWheel.enabled = FALSE;
+ }
+
+ pEvdev->emulateWheel.button = wheelButton;
+
+ inertia = xf86SetIntOption(pInfo->options, "EmulateWheelInertia", 10);
+
+ if (inertia <= 0) {
+ xf86IDrvMsg(pInfo, X_WARNING, "Invalid EmulateWheelInertia value: %d\n",
+ inertia);
+ xf86IDrvMsg(pInfo, X_WARNING, "Using built-in inertia value.\n");
+
+ inertia = 10;
+ }
+
+ pEvdev->emulateWheel.inertia = inertia;
+
+ timeout = xf86SetIntOption(pInfo->options, "EmulateWheelTimeout", 200);
+
+ if (timeout < 0) {
+ xf86IDrvMsg(pInfo, X_WARNING, "Invalid EmulateWheelTimeout value: %d\n",
+ timeout);
+ xf86IDrvMsg(pInfo, X_WARNING, "Using built-in timeout value.\n");
+
+ timeout = 200;
+ }
+
+ pEvdev->emulateWheel.timeout = timeout;
+
+ /* Configure the Y axis or default it */
+ if (!EvdevWheelEmuHandleButtonMap(pInfo, &(pEvdev->emulateWheel.Y),
+ "YAxisMapping")) {
+ /* Default the Y axis to sane values */
+ pEvdev->emulateWheel.Y.up_button = 4;
+ pEvdev->emulateWheel.Y.down_button = 5;
+
+ /* Simpler to check just the largest value in this case */
+ /* XXX: we should post this to the server */
+ if (5 > pEvdev->num_buttons)
+ pEvdev->num_buttons = 5;
+
+ /* Display default Configuration */
+ xf86IDrvMsg(pInfo, X_CONFIG, "YAxisMapping: buttons %d and %d\n",
+ pEvdev->emulateWheel.Y.up_button,
+ pEvdev->emulateWheel.Y.down_button);
+ }
+
+
+ /* This axis should default to an unconfigured state as most people
+ are not going to expect a Horizontal wheel. */
+ EvdevWheelEmuHandleButtonMap(pInfo, &(pEvdev->emulateWheel.X),
+ "XAxisMapping");
+
+ /* Used by the inertia code */
+ pEvdev->emulateWheel.X.traveled_distance = 0;
+ pEvdev->emulateWheel.Y.traveled_distance = 0;
+
+ xf86IDrvMsg(pInfo, X_CONFIG,
+ "EmulateWheelButton: %d, "
+ "EmulateWheelInertia: %d, "
+ "EmulateWheelTimeout: %d\n",
+ pEvdev->emulateWheel.button, inertia, timeout);
+}
+
+static int
+EvdevWheelEmuSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
+ BOOL checkonly)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (atom == prop_wheel_emu)
+ {
+ if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ if (!checkonly)
+ {
+ pEvdev->emulateWheel.enabled = *((BOOL*)val->data);
+ /* Don't enable with zero inertia, otherwise we may get stuck in an
+ * infinite loop */
+ if (pEvdev->emulateWheel.inertia <= 0)
+ {
+ pEvdev->emulateWheel.inertia = 10;
+ /* We may get here before the property is actually enabled */
+ if (prop_wheel_inertia)
+ XIChangeDeviceProperty(dev, prop_wheel_inertia, XA_INTEGER,
+ 16, PropModeReplace, 1,
+ &pEvdev->emulateWheel.inertia, TRUE);
+ }
+ }
+ }
+ else if (atom == prop_wheel_button)
+ {
+ int bt;
+
+ if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ bt = *((CARD8*)val->data);
+
+ if (bt < 0 || bt >= EVDEV_MAXBUTTONS)
+ return BadValue;
+
+ if (!checkonly)
+ pEvdev->emulateWheel.button = bt;
+ } else if (atom == prop_wheel_axismap)
+ {
+ if (val->format != 8 || val->size != 4 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ if (!checkonly)
+ {
+ pEvdev->emulateWheel.X.up_button = *((CARD8*)val->data);
+ pEvdev->emulateWheel.X.down_button = *(((CARD8*)val->data) + 1);
+ pEvdev->emulateWheel.Y.up_button = *(((CARD8*)val->data) + 2);
+ pEvdev->emulateWheel.Y.down_button = *(((CARD8*)val->data) + 3);
+ }
+ } else if (atom == prop_wheel_inertia)
+ {
+ int inertia;
+
+ if (val->format != 16 || val->size != 1 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ inertia = *((CARD16*)val->data);
+
+ if (inertia < 0)
+ return BadValue;
+
+ if (!checkonly)
+ pEvdev->emulateWheel.inertia = inertia;
+ } else if (atom == prop_wheel_timeout)
+ {
+ int timeout;
+
+ if (val->format != 16 || val->size != 1 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ timeout = *((CARD16*)val->data);
+
+ if (timeout < 0)
+ return BadValue;
+
+ if (!checkonly)
+ pEvdev->emulateWheel.timeout = timeout;
+ }
+ return Success;
+}
+
+void
+EvdevWheelEmuInitProperty(DeviceIntPtr dev)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+ int rc = TRUE;
+ char vals[4];
+
+ if (!dev->button) /* don't init prop for keyboards */
+ return;
+
+ prop_wheel_emu = MakeAtom(EVDEV_PROP_WHEEL, strlen(EVDEV_PROP_WHEEL), TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_wheel_emu, XA_INTEGER, 8,
+ PropModeReplace, 1,
+ &pEvdev->emulateWheel.enabled, FALSE);
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_wheel_emu, FALSE);
+
+ vals[0] = pEvdev->emulateWheel.X.up_button;
+ vals[1] = pEvdev->emulateWheel.X.down_button;
+ vals[2] = pEvdev->emulateWheel.Y.up_button;
+ vals[3] = pEvdev->emulateWheel.Y.down_button;
+
+ prop_wheel_axismap = MakeAtom(EVDEV_PROP_WHEEL_AXES, strlen(EVDEV_PROP_WHEEL_AXES), TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_wheel_axismap, XA_INTEGER, 8,
+ PropModeReplace, 4, vals, FALSE);
+
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_wheel_axismap, FALSE);
+
+ prop_wheel_inertia = MakeAtom(EVDEV_PROP_WHEEL_INERTIA, strlen(EVDEV_PROP_WHEEL_INERTIA), TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_wheel_inertia, XA_INTEGER, 16,
+ PropModeReplace, 1,
+ &pEvdev->emulateWheel.inertia, FALSE);
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_wheel_inertia, FALSE);
+
+ prop_wheel_timeout = MakeAtom(EVDEV_PROP_WHEEL_TIMEOUT, strlen(EVDEV_PROP_WHEEL_TIMEOUT), TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_wheel_timeout, XA_INTEGER, 16,
+ PropModeReplace, 1,
+ &pEvdev->emulateWheel.timeout, FALSE);
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_wheel_timeout, FALSE);
+
+ prop_wheel_button = MakeAtom(EVDEV_PROP_WHEEL_BUTTON, strlen(EVDEV_PROP_WHEEL_BUTTON), TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_wheel_button, XA_INTEGER, 8,
+ PropModeReplace, 1,
+ &pEvdev->emulateWheel.button, FALSE);
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_wheel_button, FALSE);
+
+ XIRegisterPropertyHandler(dev, EvdevWheelEmuSetProperty, NULL, NULL);
+}
diff --git a/src/evdev.c b/src/evdev.c
new file mode 100644
index 0000000..54772c7
--- /dev/null
+++ b/src/evdev.c
@@ -0,0 +1,2969 @@
+/*
+ * Copyright © 2004-2008 Red Hat, Inc.
+ *
+ * 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 Red Hat
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission. Red
+ * Hat makes 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.
+ *
+ * Authors:
+ * Kristian Høgsberg (krh@redhat.com)
+ * Adam Jackson (ajax@redhat.com)
+ * Peter Hutterer (peter.hutterer@redhat.com)
+ * Oliver McFadden (oliver.mcfadden@nokia.com)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "evdev.h"
+
+#include <X11/keysym.h>
+#include <X11/extensions/XI.h>
+
+#include <linux/version.h>
+#include <sys/stat.h>
+#include <libudev.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <xf86.h>
+#include <xf86Xinput.h>
+#include <exevents.h>
+#include <xorgVersion.h>
+#include <xkbsrv.h>
+
+#include <X11/Xatom.h>
+#include <evdev-properties.h>
+#include <xserver-properties.h>
+
+#ifndef XI_PROP_PRODUCT_ID
+#define XI_PROP_PRODUCT_ID "Device Product ID"
+#endif
+
+#ifndef XI_PROP_VIRTUAL_DEVICE
+#define XI_PROP_VIRTUAL_DEVICE "Virtual Device"
+#endif
+
+/* removed from server, purge when dropping support for server 1.10 */
+#define XI86_SEND_DRAG_EVENTS 0x08
+
+#ifndef MAXDEVICES
+#include <inputstr.h> /* for MAX_DEVICES */
+#define MAXDEVICES MAX_DEVICES
+#endif
+
+#define ArrayLength(a) (sizeof(a) / (sizeof((a)[0])))
+
+#define MIN_KEYCODE 8
+#define GLYPHS_PER_KEY 2
+#define AltMask Mod1Mask
+#define NumLockMask Mod2Mask
+#define AltLangMask Mod3Mask
+#define KanaMask Mod4Mask
+#define ScrollLockMask Mod5Mask
+
+#define CAPSFLAG 1
+#define NUMFLAG 2
+#define SCROLLFLAG 4
+#define MODEFLAG 8
+#define COMPOSEFLAG 16
+
+#ifndef ABS_MT_SLOT
+#define ABS_MT_SLOT 0x2f
+#endif
+
+#ifndef ABS_MT_TRACKING_ID
+#define ABS_MT_TRACKING_ID 0x39
+#endif
+
+static const char *evdevDefaults[] = {
+ "XkbRules", "evdev",
+ "XkbModel", "evdev",
+ "XkbLayout", "us",
+ NULL
+};
+
+/* Any of those triggers a proximity event */
+static int proximity_bits[] = {
+ BTN_TOOL_PEN,
+ BTN_TOOL_RUBBER,
+ BTN_TOOL_BRUSH,
+ BTN_TOOL_PENCIL,
+ BTN_TOOL_AIRBRUSH,
+ BTN_TOOL_FINGER,
+ BTN_TOOL_MOUSE,
+ BTN_TOOL_LENS,
+};
+
+static int EvdevOn(DeviceIntPtr);
+static int EvdevCache(InputInfoPtr pInfo);
+static void EvdevKbdCtrl(DeviceIntPtr device, KeybdCtrl *ctrl);
+static int EvdevSwitchMode(ClientPtr client, DeviceIntPtr device, int mode);
+static BOOL EvdevGrabDevice(InputInfoPtr pInfo, int grab, int ungrab);
+static void EvdevSetCalibration(InputInfoPtr pInfo, int num_calibration, int calibration[4]);
+static int EvdevOpenDevice(InputInfoPtr pInfo);
+static void EvdevCloseDevice(InputInfoPtr pInfo);
+
+static void EvdevInitAxesLabels(EvdevPtr pEvdev, int mode, int natoms, Atom *atoms);
+static void EvdevInitButtonLabels(EvdevPtr pEvdev, int natoms, Atom *atoms);
+static void EvdevInitProperty(DeviceIntPtr dev);
+static int EvdevSetProperty(DeviceIntPtr dev, Atom atom,
+ XIPropertyValuePtr val, BOOL checkonly);
+static Atom prop_product_id;
+static Atom prop_invert;
+static Atom prop_calibration;
+static Atom prop_swap;
+static Atom prop_axis_label;
+static Atom prop_btn_label;
+static Atom prop_device;
+static Atom prop_virtual;
+
+/* All devices the evdev driver has allocated and knows about.
+ * MAXDEVICES is safe as null-terminated array, as two devices (VCP and VCK)
+ * cannot be used by evdev, leaving us with a space of 2 at the end. */
+static EvdevPtr evdev_devices[MAXDEVICES] = {NULL};
+
+static int EvdevSwitchMode(ClientPtr client, DeviceIntPtr device, int mode)
+{
+ InputInfoPtr pInfo;
+ EvdevPtr pEvdev;
+
+ pInfo = device->public.devicePrivate;
+ pEvdev = pInfo->private;
+
+ if (pEvdev->flags & EVDEV_RELATIVE_EVENTS)
+ {
+ if (mode == Relative)
+ return Success;
+ else
+ return XI_BadMode;
+ }
+
+ switch (mode) {
+ case Absolute:
+ pEvdev->flags &= ~EVDEV_RELATIVE_MODE;
+ break;
+
+ case Relative:
+ pEvdev->flags |= EVDEV_RELATIVE_MODE;
+ break;
+
+ default:
+ return XI_BadMode;
+ }
+
+ return Success;
+}
+
+static size_t EvdevCountBits(unsigned long *array, size_t nlongs)
+{
+ unsigned int i;
+ size_t count = 0;
+
+ for (i = 0; i < nlongs; i++) {
+ unsigned long x = array[i];
+
+ while (x > 0)
+ {
+ count += (x & 0x1);
+ x >>= 1;
+ }
+ }
+ return count;
+}
+
+static inline int EvdevBitIsSet(const unsigned long *array, int bit)
+{
+ return !!(array[bit / LONG_BITS] & (1LL << (bit % LONG_BITS)));
+}
+
+static inline void EvdevSetBit(unsigned long *array, int bit)
+{
+ array[bit / LONG_BITS] |= (1LL << (bit % LONG_BITS));
+}
+
+static int
+EvdevGetMajorMinor(InputInfoPtr pInfo)
+{
+ struct stat st;
+
+ if (fstat(pInfo->fd, &st) == -1)
+ {
+ xf86IDrvMsg(pInfo, X_ERROR, "stat failed (%s). cannot check for duplicates.\n",
+ strerror(errno));
+ return 0;
+ }
+
+ return st.st_rdev;
+}
+
+/**
+ * Return TRUE if one of the devices we know about has the same min/maj
+ * number.
+ */
+static BOOL
+EvdevIsDuplicate(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ EvdevPtr* dev = evdev_devices;
+
+ if (pEvdev->min_maj)
+ {
+ while(*dev)
+ {
+ if ((*dev) != pEvdev &&
+ (*dev)->min_maj &&
+ (*dev)->min_maj == pEvdev->min_maj)
+ return TRUE;
+ dev++;
+ }
+ }
+ return FALSE;
+}
+
+/**
+ * Add to internal device list.
+ */
+static void
+EvdevAddDevice(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ EvdevPtr* dev = evdev_devices;
+
+ while(*dev)
+ dev++;
+
+ *dev = pEvdev;
+}
+
+/**
+ * Remove from internal device list.
+ */
+static void
+EvdevRemoveDevice(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ EvdevPtr *dev = evdev_devices;
+ int count = 0;
+
+ while(*dev)
+ {
+ count++;
+ if (*dev == pEvdev)
+ {
+ memmove(dev, dev + 1,
+ sizeof(evdev_devices) - (count * sizeof(EvdevPtr)));
+ break;
+ }
+ dev++;
+ }
+}
+
+
+static void
+SetXkbOption(InputInfoPtr pInfo, const char *name, char **option)
+{
+ char *s;
+
+ if ((s = xf86SetStrOption(pInfo->options, name, NULL))) {
+ if (!s[0]) {
+ free(s);
+ *option = NULL;
+ } else {
+ *option = s;
+ }
+ }
+}
+
+static BOOL
+EvdevDeviceIsVirtual(const char* devicenode)
+{
+ struct udev *udev = NULL;
+ struct udev_device *device = NULL;
+ struct stat st;
+ int rc = FALSE;
+ const char *devpath;
+
+ udev = udev_new();
+ if (!udev)
+ goto out;
+
+ stat(devicenode, &st);
+ device = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
+
+ if (!device)
+ goto out;
+
+
+ devpath = udev_device_get_devpath(device);
+ if (!devpath)
+ goto out;
+
+ if (strstr(devpath, "LNXSYSTM"))
+ rc = TRUE;
+
+out:
+ udev_device_unref(device);
+ udev_unref(udev);
+ return rc;
+}
+
+#ifndef HAVE_SMOOTH_SCROLLING
+static int wheel_up_button = 4;
+static int wheel_down_button = 5;
+static int wheel_left_button = 6;
+static int wheel_right_button = 7;
+#endif
+
+static EventQueuePtr
+EvdevNextInQueue(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (pEvdev->num_queue >= EVDEV_MAXQUEUE)
+ {
+ xf86IDrvMsg(pInfo, X_NONE, "dropping event due to full queue!\n");
+ return NULL;
+ }
+
+ pEvdev->num_queue++;
+ return &pEvdev->queue[pEvdev->num_queue - 1];
+}
+
+void
+EvdevQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value)
+{
+ int code = ev->code + MIN_KEYCODE;
+ EventQueuePtr pQueue;
+
+ /* Filter all repeated events from device.
+ We'll do softrepeat in the server, but only since 1.6 */
+ if (value == 2)
+ return;
+
+ if ((pQueue = EvdevNextInQueue(pInfo)))
+ {
+ pQueue->type = EV_QUEUE_KEY;
+ pQueue->detail.key = code;
+ pQueue->val = value;
+ }
+}
+
+void
+EvdevQueueButtonEvent(InputInfoPtr pInfo, int button, int value)
+{
+ EventQueuePtr pQueue;
+
+ if ((pQueue = EvdevNextInQueue(pInfo)))
+ {
+ pQueue->type = EV_QUEUE_BTN;
+ pQueue->detail.key = button;
+ pQueue->val = value;
+ }
+}
+
+void
+EvdevQueueProximityEvent(InputInfoPtr pInfo, int value)
+{
+ EventQueuePtr pQueue;
+ if ((pQueue = EvdevNextInQueue(pInfo)))
+ {
+ pQueue->type = EV_QUEUE_PROXIMITY;
+ pQueue->detail.key = 0;
+ pQueue->val = value;
+ }
+}
+
+#ifdef MULTITOUCH
+void
+EvdevQueueTouchEvent(InputInfoPtr pInfo, unsigned int touch, ValuatorMask *mask,
+ uint16_t evtype)
+{
+ EventQueuePtr pQueue;
+ if ((pQueue = EvdevNextInQueue(pInfo)))
+ {
+ pQueue->type = EV_QUEUE_TOUCH;
+ pQueue->detail.touch = touch;
+ valuator_mask_copy(pQueue->touchMask, mask);
+ pQueue->val = evtype;
+ }
+}
+#endif
+
+/**
+ * Post button event right here, right now.
+ * Interface for MB emulation since these need to post immediately.
+ */
+void
+EvdevPostButtonEvent(InputInfoPtr pInfo, int button, enum ButtonAction act)
+{
+ xf86PostButtonEvent(pInfo->dev, Relative, button,
+ (act == BUTTON_PRESS) ? 1 : 0, 0, 0);
+}
+
+void
+EvdevQueueButtonClicks(InputInfoPtr pInfo, int button, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++) {
+ EvdevQueueButtonEvent(pInfo, button, 1);
+ EvdevQueueButtonEvent(pInfo, button, 0);
+ }
+}
+
+/**
+ * Take the valuators and process them accordingly.
+ */
+static void
+EvdevProcessValuators(InputInfoPtr pInfo)
+{
+ int tmp;
+ EvdevPtr pEvdev = pInfo->private;
+ int *delta = pEvdev->delta;
+
+ /* convert to relative motion for touchpads */
+ if (pEvdev->abs_queued && (pEvdev->flags & EVDEV_RELATIVE_MODE)) {
+ if (pEvdev->in_proximity) {
+ if (valuator_mask_isset(pEvdev->vals, 0))
+ {
+ if (valuator_mask_isset(pEvdev->old_vals, 0))
+ delta[REL_X] = valuator_mask_get(pEvdev->vals, 0) -
+ valuator_mask_get(pEvdev->old_vals, 0);
+ valuator_mask_set(pEvdev->old_vals, 0,
+ valuator_mask_get(pEvdev->vals, 0));
+ }
+ if (valuator_mask_isset(pEvdev->vals, 1))
+ {
+ if (valuator_mask_isset(pEvdev->old_vals, 1))
+ delta[REL_Y] = valuator_mask_get(pEvdev->vals, 1) -
+ valuator_mask_get(pEvdev->old_vals, 1);
+ valuator_mask_set(pEvdev->old_vals, 1,
+ valuator_mask_get(pEvdev->vals, 1));
+ }
+ } else {
+ valuator_mask_zero(pEvdev->old_vals);
+ }
+ valuator_mask_zero(pEvdev->vals);
+ pEvdev->abs_queued = 0;
+ pEvdev->rel_queued = 1;
+ }
+
+ if (pEvdev->rel_queued) {
+ int i;
+
+ if (pEvdev->swap_axes) {
+ tmp = pEvdev->delta[REL_X];
+ pEvdev->delta[REL_X] = pEvdev->delta[REL_Y];
+ pEvdev->delta[REL_Y] = tmp;
+ if (pEvdev->delta[REL_X] == 0)
+ valuator_mask_unset(pEvdev->vals, REL_X);
+ if (pEvdev->delta[REL_Y] == 0)
+ valuator_mask_unset(pEvdev->vals, REL_Y);
+ }
+ if (pEvdev->invert_x)
+ pEvdev->delta[REL_X] *= -1;
+ if (pEvdev->invert_y)
+ pEvdev->delta[REL_Y] *= -1;
+
+
+ Evdev3BEmuProcessRelMotion(pInfo,
+ pEvdev->delta[REL_X],
+ pEvdev->delta[REL_Y]);
+
+ for (i = 0; i < REL_CNT; i++)
+ {
+ int map = pEvdev->axis_map[i];
+ if (pEvdev->delta[i] && map != -1)
+ valuator_mask_set(pEvdev->vals, map, pEvdev->delta[i]);
+ }
+ }
+ /*
+ * Some devices only generate valid abs coords when BTN_TOOL_PEN is
+ * pressed. On wacom tablets, this means that the pen is in
+ * proximity of the tablet. After the pen is removed, BTN_TOOL_PEN is
+ * released, and a (0, 0) absolute event is generated. Checking
+ * pEvdev->in_proximity here lets us ignore that event. pEvdev is
+ * initialized to 1 so devices that don't use this scheme still
+ * just works.
+ */
+ else if (pEvdev->abs_queued && pEvdev->in_proximity) {
+ int i;
+
+ if (pEvdev->swap_axes) {
+ int swapped_isset[2] = {0, 0};
+ int swapped_values[2];
+
+ for(i = 0; i <= 1; i++)
+ if (valuator_mask_isset(pEvdev->vals, i)) {
+ swapped_isset[1 - i] = 1;
+ swapped_values[1 - i] =
+ xf86ScaleAxis(valuator_mask_get(pEvdev->vals, i),
+ pEvdev->absinfo[1 - i].maximum,
+ pEvdev->absinfo[1 - i].minimum,
+ pEvdev->absinfo[i].maximum,
+ pEvdev->absinfo[i].minimum);
+ }
+
+ for (i = 0; i <= 1; i++)
+ if (swapped_isset[i])
+ valuator_mask_set(pEvdev->vals, i, swapped_values[i]);
+ else
+ valuator_mask_unset(pEvdev->vals, i);
+ }
+
+ for (i = 0; i <= 1; i++) {
+ int val;
+ int calib_min;
+ int calib_max;
+
+ if (!valuator_mask_isset(pEvdev->vals, i))
+ continue;
+
+ val = valuator_mask_get(pEvdev->vals, i);
+
+ if (i == 0) {
+ calib_min = pEvdev->calibration.min_x;
+ calib_max = pEvdev->calibration.max_x;
+ } else {
+ calib_min = pEvdev->calibration.min_y;
+ calib_max = pEvdev->calibration.max_y;
+ }
+
+ if (pEvdev->flags & EVDEV_CALIBRATED)
+ val = xf86ScaleAxis(val, pEvdev->absinfo[i].maximum,
+ pEvdev->absinfo[i].minimum, calib_max,
+ calib_min);
+
+ if ((i == 0 && pEvdev->invert_x) || (i == 1 && pEvdev->invert_y))
+ val = (pEvdev->absinfo[i].maximum - val +
+ pEvdev->absinfo[i].minimum);
+
+ valuator_mask_set(pEvdev->vals, i, val);
+ }
+ Evdev3BEmuProcessAbsMotion(pInfo, pEvdev->vals);
+ }
+}
+
+static void
+EvdevProcessProximityEvent(InputInfoPtr pInfo, struct input_event *ev)
+{
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (!pEvdev->use_proximity)
+ return;
+
+ pEvdev->prox_queued = 1;
+
+ EvdevQueueProximityEvent(pInfo, ev->value);
+}
+
+/**
+ * Proximity handling is rather weird because of tablet-specific issues.
+ * Some tablets, notably Wacoms, send a 0/0 coordinate in the same EV_SYN as
+ * the out-of-proximity notify. We need to ignore those, hence we only
+ * actually post valuator events when we're in proximity.
+ *
+ * Other tablets send the x/y coordinates, then EV_SYN, then the proximity
+ * event. For those, we need to remember x/y to post it when the proximity
+ * comes.
+ *
+ * If we're not in proximity and we get valuator events, remember that, they
+ * won't be posted though. If we move into proximity without valuators, use
+ * the last ones we got and let the rest of the code post them.
+ */
+static int
+EvdevProcessProximityState(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ int prox_state = 0;
+ int i;
+
+ /* Does this device have any proximity axes? */
+ if (!pEvdev->prox)
+ return 0;
+
+ /* no proximity change in the queue */
+ if (!pEvdev->prox_queued)
+ {
+ if (pEvdev->abs_queued && !pEvdev->in_proximity)
+ for (i = 0; i < valuator_mask_size(pEvdev->vals); i++)
+ if (valuator_mask_isset(pEvdev->vals, i))
+ valuator_mask_set(pEvdev->prox, i,
+ valuator_mask_get(pEvdev->vals, i));
+ return 0;
+ }
+
+ for (i = 0; i < pEvdev->num_queue; i++)
+ {
+ if (pEvdev->queue[i].type == EV_QUEUE_PROXIMITY)
+ {
+ prox_state = pEvdev->queue[i].val;
+ break;
+ }
+ }
+
+ if ((prox_state && !pEvdev->in_proximity) ||
+ (!prox_state && pEvdev->in_proximity))
+ {
+ /* We're about to go into/out of proximity but have no abs events
+ * within the EV_SYN. Use the last coordinates we have. */
+ for (i = 0; i < valuator_mask_size(pEvdev->prox); i++)
+ if (!valuator_mask_isset(pEvdev->vals, i) &&
+ valuator_mask_isset(pEvdev->prox, i))
+ valuator_mask_set(pEvdev->vals, i,
+ valuator_mask_get(pEvdev->prox, i));
+ valuator_mask_zero(pEvdev->prox);
+
+ pEvdev->abs_queued = valuator_mask_size(pEvdev->vals);
+ }
+
+ pEvdev->in_proximity = prox_state;
+ return 1;
+}
+
+/**
+ * Take a button input event and process it accordingly.
+ */
+static void
+EvdevProcessButtonEvent(InputInfoPtr pInfo, struct input_event *ev)
+{
+ unsigned int button;
+ int value;
+ EvdevPtr pEvdev = pInfo->private;
+
+ button = EvdevUtilButtonEventToButtonNumber(pEvdev, ev->code);
+
+ /* Get the signed value, earlier kernels had this as unsigned */
+ value = ev->value;
+
+ /* Handle drag lock */
+ if (EvdevDragLockFilterEvent(pInfo, button, value))
+ return;
+
+ if (EvdevWheelEmuFilterButton(pInfo, button, value))
+ return;
+
+ if (EvdevMBEmuFilterEvent(pInfo, button, value))
+ return;
+
+ if (button)
+ EvdevQueueButtonEvent(pInfo, button, value);
+ else
+ EvdevQueueKbdEvent(pInfo, ev, value);
+}
+
+/**
+ * Take the relative motion input event and process it accordingly.
+ */
+static void
+EvdevProcessRelativeMotionEvent(InputInfoPtr pInfo, struct input_event *ev)
+{
+ int value;
+ EvdevPtr pEvdev = pInfo->private;
+ int map;
+
+ /* Get the signed value, earlier kernels had this as unsigned */
+ value = ev->value;
+
+ switch (ev->code) {
+#ifndef HAVE_SMOOTH_SCROLLING
+ case REL_WHEEL:
+ if (value > 0)
+ EvdevQueueButtonClicks(pInfo, wheel_up_button, value);
+ else if (value < 0)
+ EvdevQueueButtonClicks(pInfo, wheel_down_button, -value);
+ break;
+
+ case REL_DIAL:
+ case REL_HWHEEL:
+ if (value > 0)
+ EvdevQueueButtonClicks(pInfo, wheel_right_button, value);
+ else if (value < 0)
+ EvdevQueueButtonClicks(pInfo, wheel_left_button, -value);
+ break;
+ /* We don't post wheel events as axis motion. */
+#endif
+ default:
+ /* Ignore EV_REL events if we never set up for them. */
+ if (!(pEvdev->flags & EVDEV_RELATIVE_EVENTS))
+ return;
+
+ /* Handle mouse wheel emulation */
+ if (EvdevWheelEmuFilterMotion(pInfo, ev))
+ return;
+
+ pEvdev->rel_queued = 1;
+ pEvdev->delta[ev->code] += value;
+ map = pEvdev->axis_map[ev->code];
+ valuator_mask_set(pEvdev->vals, map, value);
+ break;
+ }
+}
+
+#ifdef MULTITOUCH
+static void
+EvdevProcessTouch(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ int type;
+
+ if (pEvdev->cur_slot < 0 || !pEvdev->mt_mask)
+ return;
+
+ /* If the ABS_MT_SLOT is the first event we get after EV_SYN, skip this */
+ if (pEvdev->slot_state == SLOTSTATE_EMPTY)
+ return;
+
+ if (pEvdev->slot_state == SLOTSTATE_CLOSE)
+ type = XI_TouchEnd;
+ else if (pEvdev->slot_state == SLOTSTATE_OPEN)
+ type = XI_TouchBegin;
+ else
+ type = XI_TouchUpdate;
+
+
+ EvdevQueueTouchEvent(pInfo, pEvdev->cur_slot, pEvdev->mt_mask, type);
+
+ pEvdev->slot_state = SLOTSTATE_EMPTY;
+
+ valuator_mask_zero(pEvdev->mt_mask);
+}
+
+static int
+num_slots(EvdevPtr pEvdev)
+{
+ int value = pEvdev->absinfo[ABS_MT_SLOT].maximum -
+ pEvdev->absinfo[ABS_MT_SLOT].minimum + 1;
+
+ /* If we don't know how many slots there are, assume at least 10 */
+ return value > 1 ? value : 10;
+}
+
+static int
+last_mt_vals_slot(EvdevPtr pEvdev)
+{
+ int value = pEvdev->cur_slot - pEvdev->absinfo[ABS_MT_SLOT].minimum;
+
+ return value < num_slots(pEvdev) ? value : -1;
+}
+
+static void
+EvdevProcessTouchEvent(InputInfoPtr pInfo, struct input_event *ev)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ int map;
+
+ if (ev->code == ABS_MT_SLOT) {
+ EvdevProcessTouch(pInfo);
+ pEvdev->cur_slot = ev->value;
+ } else
+ {
+ int slot_index = last_mt_vals_slot(pEvdev);
+
+ if (pEvdev->slot_state == SLOTSTATE_EMPTY)
+ pEvdev->slot_state = SLOTSTATE_UPDATE;
+ if (ev->code == ABS_MT_TRACKING_ID) {
+ if (ev->value >= 0) {
+ pEvdev->slot_state = SLOTSTATE_OPEN;
+
+ if (slot_index >= 0)
+ valuator_mask_copy(pEvdev->mt_mask,
+ pEvdev->last_mt_vals[slot_index]);
+ else
+ xf86IDrvMsg(pInfo, X_WARNING,
+ "Attempted to copy values from out-of-range "
+ "slot, touch events may be incorrect.\n");
+ } else
+ pEvdev->slot_state = SLOTSTATE_CLOSE;
+ } else {
+ map = pEvdev->axis_map[ev->code];
+ valuator_mask_set(pEvdev->mt_mask, map, ev->value);
+ if (slot_index >= 0)
+ valuator_mask_set(pEvdev->last_mt_vals[slot_index], map,
+ ev->value);
+ }
+ }
+}
+#else
+#define EvdevProcessTouch(pInfo)
+#define EvdevProcessTouchEvent(pInfo, ev)
+#endif /* MULTITOUCH */
+
+/**
+ * Take the absolute motion input event and process it accordingly.
+ */
+static void
+EvdevProcessAbsoluteMotionEvent(InputInfoPtr pInfo, struct input_event *ev)
+{
+ int value;
+ EvdevPtr pEvdev = pInfo->private;
+ int map;
+
+ /* Get the signed value, earlier kernels had this as unsigned */
+ value = ev->value;
+
+ /* Ignore EV_ABS events if we never set up for them. */
+ if (!(pEvdev->flags & EVDEV_ABSOLUTE_EVENTS))
+ return;
+
+ if (ev->code > ABS_MAX)
+ return;
+
+ if (EvdevWheelEmuFilterMotion(pInfo, ev))
+ return;
+
+ if (ev->code >= ABS_MT_SLOT) {
+ EvdevProcessTouchEvent(pInfo, ev);
+ pEvdev->abs_queued = 1;
+ } else if (!pEvdev->mt_mask) {
+ map = pEvdev->axis_map[ev->code];
+ valuator_mask_set(pEvdev->vals, map, value);
+ pEvdev->abs_queued = 1;
+ }
+}
+
+/**
+ * Take the key press/release input event and process it accordingly.
+ */
+static void
+EvdevProcessKeyEvent(InputInfoPtr pInfo, struct input_event *ev)
+{
+ int value, i;
+ EvdevPtr pEvdev = pInfo->private;
+
+ /* Get the signed value, earlier kernels had this as unsigned */
+ value = ev->value;
+
+ /* don't repeat mouse buttons */
+ if (ev->code >= BTN_MOUSE && ev->code < KEY_OK)
+ if (value == 2)
+ return;
+
+ for (i = 0; i < ArrayLength(proximity_bits); i++)
+ {
+ if (ev->code == proximity_bits[i])
+ {
+ EvdevProcessProximityEvent(pInfo, ev);
+ return;
+ }
+ }
+
+ switch (ev->code) {
+ case BTN_TOUCH:
+ /* For devices that have but don't use proximity, use
+ * BTN_TOUCH as the proximity notifier */
+ if (!pEvdev->use_proximity)
+ pEvdev->in_proximity = value ? ev->code : 0;
+ if (!(pEvdev->flags & (EVDEV_TOUCHSCREEN | EVDEV_TABLET)) ||
+ pEvdev->mt_mask)
+ break;
+ /* Treat BTN_TOUCH from devices that only have BTN_TOUCH as
+ * BTN_LEFT. */
+ ev->code = BTN_LEFT;
+ /* Intentional fallthrough! */
+
+ default:
+ EvdevProcessButtonEvent(pInfo, ev);
+ break;
+ }
+}
+
+/**
+ * Post the relative motion events.
+ */
+void
+EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int num_v, int first_v,
+ int v[MAX_VALUATORS])
+{
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (pEvdev->rel_queued) {
+ xf86PostMotionEventM(pInfo->dev, Relative, pEvdev->vals);
+ }
+}
+
+/**
+ * Post the absolute motion events.
+ */
+void
+EvdevPostAbsoluteMotionEvents(InputInfoPtr pInfo, int num_v, int first_v,
+ int v[MAX_VALUATORS])
+{
+ EvdevPtr pEvdev = pInfo->private;
+
+ /*
+ * Some devices only generate valid abs coords when BTN_TOOL_PEN is
+ * pressed. On wacom tablets, this means that the pen is in
+ * proximity of the tablet. After the pen is removed, BTN_TOOL_PEN is
+ * released, and a (0, 0) absolute event is generated. Checking
+ * pEvdev->in_proximity here lets us ignore that event.
+ * pEvdev->in_proximity is initialized to 1 so devices that don't use
+ * this scheme still just work.
+ */
+ if (pEvdev->abs_queued && pEvdev->in_proximity) {
+ xf86PostMotionEventM(pInfo->dev, Absolute, pEvdev->vals);
+ }
+}
+
+static void
+EvdevPostProximityEvents(InputInfoPtr pInfo, int which, int num_v, int first_v,
+ int v[MAX_VALUATORS])
+{
+ int i;
+ EvdevPtr pEvdev = pInfo->private;
+
+ for (i = 0; pEvdev->prox_queued && i < pEvdev->num_queue; i++) {
+ switch (pEvdev->queue[i].type) {
+ case EV_QUEUE_KEY:
+ case EV_QUEUE_BTN:
+#ifdef MULTITOUCH
+ case EV_QUEUE_TOUCH:
+#endif
+ break;
+ case EV_QUEUE_PROXIMITY:
+ if (pEvdev->queue[i].val == which)
+ xf86PostProximityEventP(pInfo->dev, which, first_v, num_v,
+ v + first_v);
+ break;
+ }
+ }
+}
+
+/**
+ * Post the queued key/button events.
+ */
+static void EvdevPostQueuedEvents(InputInfoPtr pInfo, int num_v, int first_v,
+ int v[MAX_VALUATORS])
+{
+ int i;
+ EvdevPtr pEvdev = pInfo->private;
+
+ for (i = 0; i < pEvdev->num_queue; i++) {
+ switch (pEvdev->queue[i].type) {
+ case EV_QUEUE_KEY:
+ xf86PostKeyboardEvent(pInfo->dev, pEvdev->queue[i].detail.key,
+ pEvdev->queue[i].val);
+ break;
+ case EV_QUEUE_BTN:
+ if (Evdev3BEmuFilterEvent(pInfo,
+ pEvdev->queue[i].detail.key,
+ pEvdev->queue[i].val))
+ break;
+
+ if (pEvdev->abs_queued && pEvdev->in_proximity) {
+ xf86PostButtonEventP(pInfo->dev, Absolute, pEvdev->queue[i].detail.key,
+ pEvdev->queue[i].val, first_v, num_v,
+ v + first_v);
+
+ } else
+ xf86PostButtonEvent(pInfo->dev, Relative, pEvdev->queue[i].detail.key,
+ pEvdev->queue[i].val, 0, 0);
+ break;
+ case EV_QUEUE_PROXIMITY:
+ break;
+#ifdef MULTITOUCH
+ case EV_QUEUE_TOUCH:
+ xf86PostTouchEvent(pInfo->dev, pEvdev->queue[i].detail.touch,
+ pEvdev->queue[i].val, 0,
+ pEvdev->queue[i].touchMask);
+ break;
+#endif
+ }
+ }
+}
+
+/**
+ * Take the synchronization input event and process it accordingly; the motion
+ * notify events are sent first, then any button/key press/release events.
+ */
+static void
+EvdevProcessSyncEvent(InputInfoPtr pInfo, struct input_event *ev)
+{
+ int i;
+ int num_v = 0, first_v = 0;
+ int v[MAX_VALUATORS] = {};
+ EvdevPtr pEvdev = pInfo->private;
+
+ EvdevProcessProximityState(pInfo);
+
+ EvdevProcessValuators(pInfo);
+ EvdevProcessTouch(pInfo);
+
+ EvdevPostProximityEvents(pInfo, TRUE, num_v, first_v, v);
+ EvdevPostRelativeMotionEvents(pInfo, num_v, first_v, v);
+ EvdevPostAbsoluteMotionEvents(pInfo, num_v, first_v, v);
+ EvdevPostQueuedEvents(pInfo, num_v, first_v, v);
+ EvdevPostProximityEvents(pInfo, FALSE, num_v, first_v, v);
+
+ memset(pEvdev->delta, 0, sizeof(pEvdev->delta));
+ for (i = 0; i < ArrayLength(pEvdev->queue); i++)
+ {
+ EventQueuePtr queue = &pEvdev->queue[i];
+ queue->detail.key = 0;
+ queue->type = 0;
+ queue->val = 0;
+ /* don't reset the touchMask */
+ }
+
+ if (pEvdev->vals)
+ valuator_mask_zero(pEvdev->vals);
+ pEvdev->num_queue = 0;
+ pEvdev->abs_queued = 0;
+ pEvdev->rel_queued = 0;
+ pEvdev->prox_queued = 0;
+
+}
+
+/**
+ * Process the events from the device; nothing is actually posted to the server
+ * until an EV_SYN event is received.
+ */
+static void
+EvdevProcessEvent(InputInfoPtr pInfo, struct input_event *ev)
+{
+ switch (ev->type) {
+ case EV_REL:
+ EvdevProcessRelativeMotionEvent(pInfo, ev);
+ break;
+ case EV_ABS:
+ EvdevProcessAbsoluteMotionEvent(pInfo, ev);
+ break;
+ case EV_KEY:
+ EvdevProcessKeyEvent(pInfo, ev);
+ break;
+ case EV_SYN:
+ EvdevProcessSyncEvent(pInfo, ev);
+ break;
+ }
+}
+
+#undef ABS_X_VALUE
+#undef ABS_Y_VALUE
+#undef ABS_VALUE
+
+static void
+EvdevFreeMasks(EvdevPtr pEvdev)
+{
+#ifdef MULTITOUCH
+ int i;
+#endif
+
+ valuator_mask_free(&pEvdev->vals);
+ valuator_mask_free(&pEvdev->old_vals);
+ valuator_mask_free(&pEvdev->prox);
+#ifdef MULTITOUCH
+ valuator_mask_free(&pEvdev->mt_mask);
+ if (pEvdev->last_mt_vals)
+ {
+ for (i = 0; i < num_slots(pEvdev); i++)
+ valuator_mask_free(&pEvdev->last_mt_vals[i]);
+ free(pEvdev->last_mt_vals);
+ pEvdev->last_mt_vals = NULL;
+ }
+ for (i = 0; i < EVDEV_MAXQUEUE; i++)
+ valuator_mask_free(&pEvdev->queue[i].touchMask);
+#endif
+}
+
+/* just a magic number to reduce the number of reads */
+#define NUM_EVENTS 16
+
+static void
+EvdevReadInput(InputInfoPtr pInfo)
+{
+ struct input_event ev[NUM_EVENTS];
+ int i, len = sizeof(ev);
+
+ while (len == sizeof(ev))
+ {
+#ifdef MULTITOUCH
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (pEvdev->mtdev)
+ len = mtdev_get(pEvdev->mtdev, pInfo->fd, ev, NUM_EVENTS) *
+ sizeof(struct input_event);
+ else
+#endif
+ len = read(pInfo->fd, &ev, sizeof(ev));
+
+ if (len <= 0)
+ {
+ if (errno == ENODEV) /* May happen after resume */
+ xf86RemoveEnabledDevice(pInfo);
+ else if (errno != EAGAIN)
+ {
+ /* We use X_NONE here because it doesn't alloc */
+ xf86MsgVerb(X_NONE, 0, "%s: Read error: %s\n", pInfo->name,
+ strerror(errno));
+ }
+ break;
+ }
+
+ /* The kernel promises that we always only read a complete
+ * event, so len != sizeof ev is an error. */
+ if (len % sizeof(ev[0])) {
+ /* We use X_NONE here because it doesn't alloc */
+ xf86MsgVerb(X_NONE, 0, "%s: Read error: %s\n", pInfo->name, strerror(errno));
+ break;
+ }
+
+ for (i = 0; i < len/sizeof(ev[0]); i++)
+ EvdevProcessEvent(pInfo, &ev[i]);
+ }
+}
+
+static void
+EvdevPtrCtrlProc(DeviceIntPtr device, PtrCtrl *ctrl)
+{
+ /* Nothing to do, dix handles all settings */
+}
+
+static void
+EvdevKbdCtrl(DeviceIntPtr device, KeybdCtrl *ctrl)
+{
+ static struct { int xbit, code; } bits[] = {
+ { CAPSFLAG, LED_CAPSL },
+ { NUMFLAG, LED_NUML },
+ { SCROLLFLAG, LED_SCROLLL },
+ { MODEFLAG, LED_KANA },
+ { COMPOSEFLAG, LED_COMPOSE }
+ };
+
+ InputInfoPtr pInfo;
+ struct input_event ev[ArrayLength(bits)];
+ int i;
+
+ memset(ev, 0, sizeof(ev));
+
+ pInfo = device->public.devicePrivate;
+ for (i = 0; i < ArrayLength(bits); i++) {
+ ev[i].type = EV_LED;
+ ev[i].code = bits[i].code;
+ ev[i].value = (ctrl->leds & bits[i].xbit) > 0;
+ }
+
+ write(pInfo->fd, ev, sizeof ev);
+}
+
+static int
+EvdevAddKeyClass(DeviceIntPtr device)
+{
+ InputInfoPtr pInfo;
+ EvdevPtr pEvdev;
+
+ pInfo = device->public.devicePrivate;
+ pEvdev = pInfo->private;
+
+ /* sorry, no rules change allowed for you */
+ xf86ReplaceStrOption(pInfo->options, "xkb_rules", "evdev");
+ SetXkbOption(pInfo, "xkb_rules", &pEvdev->rmlvo.rules);
+ SetXkbOption(pInfo, "xkb_model", &pEvdev->rmlvo.model);
+ if (!pEvdev->rmlvo.model)
+ SetXkbOption(pInfo, "XkbModel", &pEvdev->rmlvo.model);
+ SetXkbOption(pInfo, "xkb_layout", &pEvdev->rmlvo.layout);
+ if (!pEvdev->rmlvo.layout)
+ SetXkbOption(pInfo, "XkbLayout", &pEvdev->rmlvo.layout);
+ SetXkbOption(pInfo, "xkb_variant", &pEvdev->rmlvo.variant);
+ if (!pEvdev->rmlvo.variant)
+ SetXkbOption(pInfo, "XkbVariant", &pEvdev->rmlvo.variant);
+ SetXkbOption(pInfo, "xkb_options", &pEvdev->rmlvo.options);
+ if (!pEvdev->rmlvo.options)
+ SetXkbOption(pInfo, "XkbOptions", &pEvdev->rmlvo.options);
+
+ if (!InitKeyboardDeviceStruct(device, &pEvdev->rmlvo, NULL, EvdevKbdCtrl))
+ return !Success;
+
+ return Success;
+}
+
+#ifdef MULTITOUCH
+/* MT axes are counted twice - once as ABS_X (which the kernel keeps for
+ * backwards compatibility), once as ABS_MT_POSITION_X. So we need to keep a
+ * mapping of those axes to make sure we only count them once
+ */
+struct mt_axis_mappings {
+ int mt_code;
+ int code;
+ Bool needs_mapping; /* TRUE if both code and mt_code are present */
+ int mapping; /* Logical mapping of 'code' axis */
+};
+
+static struct mt_axis_mappings mt_axis_mappings[] = {
+ {ABS_MT_POSITION_X, ABS_X},
+ {ABS_MT_POSITION_Y, ABS_Y},
+ {ABS_MT_PRESSURE, ABS_PRESSURE},
+ {ABS_MT_DISTANCE, ABS_DISTANCE},
+};
+#endif
+
+/**
+ * return TRUE if the axis is not one we should count as true axis
+ */
+static int
+is_blacklisted_axis(int axis)
+{
+ switch(axis)
+ {
+ case ABS_MT_SLOT:
+ case ABS_MT_TRACKING_ID:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+
+static int
+EvdevAddAbsValuatorClass(DeviceIntPtr device)
+{
+ InputInfoPtr pInfo;
+ EvdevPtr pEvdev;
+ int num_axes, axis, i = 0;
+ int num_mt_axes = 0, /* number of MT-only axes */
+ num_mt_axes_total = 0; /* total number of MT axes, including
+ double-counted ones, excluding blacklisted */
+ Atom *atoms;
+
+ pInfo = device->public.devicePrivate;
+ pEvdev = pInfo->private;
+
+ if (!EvdevBitIsSet(pEvdev->bitmask, EV_ABS))
+ goto out;
+
+ num_axes = EvdevCountBits(pEvdev->abs_bitmask, NLONGS(ABS_MAX));
+ if (num_axes < 1)
+ goto out;
+
+#ifdef MULTITOUCH
+ for (axis = ABS_MT_SLOT; axis < ABS_MAX; axis++)
+ {
+ if (EvdevBitIsSet(pEvdev->abs_bitmask, axis))
+ {
+ int j;
+ Bool skip = FALSE;
+
+ for (j = 0; j < ArrayLength(mt_axis_mappings); j++)
+ {
+ if (mt_axis_mappings[j].mt_code == axis &&
+ BitIsOn(pEvdev->abs_bitmask, mt_axis_mappings[j].code))
+ {
+ mt_axis_mappings[j].needs_mapping = TRUE;
+ skip = TRUE;
+ }
+ }
+
+ if (!is_blacklisted_axis(axis))
+ {
+ num_mt_axes_total++;
+ if (!skip)
+ num_mt_axes++;
+ }
+ num_axes--;
+ }
+ }
+#endif
+ if (num_axes + num_mt_axes > MAX_VALUATORS) {
+ xf86IDrvMsg(pInfo, X_WARNING, "found %d axes, limiting to %d.\n", num_axes, MAX_VALUATORS);
+ num_axes = MAX_VALUATORS;
+ }
+
+ if (num_axes < 1 && num_mt_axes_total < 1) {
+ xf86Msg(X_WARNING, "%s: no absolute or touch axes found.\n",
+ device->name);
+ return !Success;
+ }
+
+ pEvdev->num_vals = num_axes;
+ if (num_axes > 0) {
+ pEvdev->vals = valuator_mask_new(num_axes);
+ pEvdev->old_vals = valuator_mask_new(num_axes);
+ if (!pEvdev->vals || !pEvdev->old_vals) {
+ xf86IDrvMsg(pInfo, X_ERROR, "failed to allocate valuator masks.\n");
+ goto out;
+ }
+ }
+#ifdef MULTITOUCH
+ if (num_mt_axes_total > 0) {
+ pEvdev->num_mt_vals = num_mt_axes_total;
+ pEvdev->mt_mask = valuator_mask_new(num_mt_axes_total);
+ if (!pEvdev->mt_mask) {
+ xf86Msg(X_ERROR, "%s: failed to allocate MT valuator mask.\n",
+ device->name);
+ goto out;
+ }
+
+ pEvdev->last_mt_vals = calloc(num_slots(pEvdev), sizeof(ValuatorMask *));
+ if (!pEvdev->last_mt_vals) {
+ xf86IDrvMsg(pInfo, X_ERROR,
+ "%s: failed to allocate MT last values mask array.\n",
+ device->name);
+ goto out;
+ }
+
+ for (i = 0; i < num_slots(pEvdev); i++) {
+ pEvdev->last_mt_vals[i] = valuator_mask_new(num_mt_axes_total);
+ if (!pEvdev->last_mt_vals[i]) {
+ xf86IDrvMsg(pInfo, X_ERROR,
+ "%s: failed to allocate MT last values mask.\n",
+ device->name);
+ goto out;
+ }
+ }
+
+ for (i = 0; i < EVDEV_MAXQUEUE; i++) {
+ pEvdev->queue[i].touchMask =
+ valuator_mask_new(num_mt_axes_total);
+ if (!pEvdev->queue[i].touchMask) {
+ xf86Msg(X_ERROR, "%s: failed to allocate MT valuator masks for "
+ "evdev event queue.\n", device->name);
+ goto out;
+ }
+ }
+ }
+#endif
+ atoms = malloc((pEvdev->num_vals + num_mt_axes) * sizeof(Atom));
+
+ i = 0;
+ for (axis = ABS_X; i < MAX_VALUATORS && axis <= ABS_MAX; axis++) {
+#ifdef MULTITOUCH
+ int j;
+#endif
+ int mapping;
+ pEvdev->axis_map[axis] = -1;
+ if (!EvdevBitIsSet(pEvdev->abs_bitmask, axis) ||
+ is_blacklisted_axis(axis))
+ continue;
+
+ mapping = i;
+
+#ifdef MULTITOUCH
+ for (j = 0; j < ArrayLength(mt_axis_mappings); j++)
+ {
+ if (mt_axis_mappings[j].code == axis)
+ mt_axis_mappings[j].mapping = mapping;
+ else if (mt_axis_mappings[j].mt_code == axis &&
+ mt_axis_mappings[j].needs_mapping)
+ mapping = mt_axis_mappings[j].mapping;
+ }
+#endif
+ pEvdev->axis_map[axis] = mapping;
+ if (mapping == i)
+ i++;
+ }
+
+ EvdevInitAxesLabels(pEvdev, Absolute, pEvdev->num_vals + num_mt_axes, atoms);
+
+ if (!InitValuatorClassDeviceStruct(device, num_axes + num_mt_axes, atoms,
+ GetMotionHistorySize(), Absolute)) {
+ xf86IDrvMsg(pInfo, X_ERROR, "failed to initialize valuator class device.\n");
+ goto out;
+ }
+
+#ifdef MULTITOUCH
+ if (num_mt_axes_total > 0)
+ {
+ int num_touches = 0;
+ int mode = pEvdev->flags & EVDEV_TOUCHPAD ?
+ XIDependentTouch : XIDirectTouch;
+
+ if (pEvdev->mtdev->caps.slot.maximum > 0)
+ num_touches = pEvdev->mtdev->caps.slot.maximum -
+ pEvdev->mtdev->caps.slot.minimum + 1;
+
+ if (!InitTouchClassDeviceStruct(device, num_touches, mode,
+ num_mt_axes_total)) {
+ xf86Msg(X_ERROR, "%s: failed to initialize touch class device.\n",
+ device->name);
+ goto out;
+ }
+
+ for (i = 0; i < num_slots(pEvdev); i++) {
+ for (axis = ABS_MT_TOUCH_MAJOR; axis < ABS_MAX; axis++) {
+ if (pEvdev->axis_map[axis] >= 0) {
+ /* XXX: read initial values from mtdev when it adds support
+ * for doing so. */
+ valuator_mask_set(pEvdev->last_mt_vals[i],
+ pEvdev->axis_map[axis], 0);
+ }
+ }
+ }
+ }
+#endif
+
+ for (axis = ABS_X; axis < ABS_MT_SLOT; axis++) {
+ int axnum = pEvdev->axis_map[axis];
+ int resolution = 0;
+
+ if (axnum == -1)
+ continue;
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 30)
+ /* Kernel provides units/mm, X wants units/m */
+ if (pEvdev->absinfo[axis].resolution)
+ resolution = pEvdev->absinfo[axis].resolution * 1000;
+#endif
+
+ xf86InitValuatorAxisStruct(device, axnum,
+ atoms[axnum],
+ pEvdev->absinfo[axis].minimum,
+ pEvdev->absinfo[axis].maximum,
+ resolution, 0, resolution, Absolute);
+ xf86InitValuatorDefaults(device, axnum);
+ }
+
+#ifdef MULTITOUCH
+ for (axis = ABS_MT_TOUCH_MAJOR; axis <= ABS_MAX; axis++) {
+ int axnum = pEvdev->axis_map[axis];
+ int resolution = 0;
+ int j;
+ BOOL skip = FALSE;
+
+ if (axnum < 0)
+ continue;
+
+ for (j = 0; j < ArrayLength(mt_axis_mappings); j++)
+ if (mt_axis_mappings[j].mt_code == axis &&
+ mt_axis_mappings[j].needs_mapping)
+ {
+ skip = TRUE;
+ break;
+ }
+
+ /* MT axis is mapped, don't set up twice */
+ if (skip)
+ continue;
+
+ if (pEvdev->absinfo[axis].resolution)
+ resolution = pEvdev->absinfo[axis].resolution * 1000;
+
+ xf86InitValuatorAxisStruct(device, axnum,
+ atoms[axnum],
+ pEvdev->absinfo[axis].minimum,
+ pEvdev->absinfo[axis].maximum,
+ resolution, 0, resolution,
+ Absolute);
+ }
+#endif
+
+ free(atoms);
+
+ for (i = 0; i < ArrayLength(proximity_bits); i++)
+ {
+ if (!pEvdev->use_proximity)
+ break;
+
+ if (EvdevBitIsSet(pEvdev->key_bitmask, proximity_bits[i]))
+ {
+ InitProximityClassDeviceStruct(device);
+ pEvdev->prox = valuator_mask_new(num_axes);
+ if (!pEvdev->prox) {
+ xf86IDrvMsg(pInfo, X_ERROR,
+ "failed to allocate proximity valuator " "mask.\n");
+ goto out;
+ }
+ break;
+ }
+ }
+
+ if (!InitPtrFeedbackClassDeviceStruct(device, EvdevPtrCtrlProc)) {
+ xf86IDrvMsg(pInfo, X_ERROR,
+ "failed to initialize pointer feedback class device.\n");
+ goto out;
+ }
+
+ if (pEvdev->flags & EVDEV_TOUCHPAD)
+ pEvdev->flags |= EVDEV_RELATIVE_MODE;
+ else
+ pEvdev->flags &= ~EVDEV_RELATIVE_MODE;
+
+ if (xf86FindOption(pInfo->options, "Mode"))
+ {
+ char *mode;
+ mode = xf86SetStrOption(pInfo->options, "Mode", NULL);
+ if (!strcasecmp("absolute", mode))
+ pEvdev->flags &= ~EVDEV_RELATIVE_MODE;
+ else if (!strcasecmp("relative", mode))
+ pEvdev->flags |= EVDEV_RELATIVE_MODE;
+ else
+ xf86IDrvMsg(pInfo, X_INFO, "unknown mode, use default\n");
+ free(mode);
+ }
+
+ return Success;
+
+out:
+ EvdevFreeMasks(pEvdev);
+ return !Success;
+}
+
+static int
+EvdevAddRelValuatorClass(DeviceIntPtr device)
+{
+ InputInfoPtr pInfo;
+ EvdevPtr pEvdev;
+ int num_axes, axis, i = 0;
+ Atom *atoms;
+
+ pInfo = device->public.devicePrivate;
+ pEvdev = pInfo->private;
+
+ if (!EvdevBitIsSet(pEvdev->bitmask, EV_REL))
+ goto out;
+
+ num_axes = EvdevCountBits(pEvdev->rel_bitmask, NLONGS(REL_MAX));
+ if (num_axes < 1)
+ goto out;
+
+#ifndef HAVE_SMOOTH_SCROLLING
+ /* Wheels are special, we post them as button events. So let's ignore them
+ * in the axes list too */
+ if (EvdevBitIsSet(pEvdev->rel_bitmask, REL_WHEEL))
+ num_axes--;
+ if (EvdevBitIsSet(pEvdev->rel_bitmask, REL_HWHEEL))
+ num_axes--;
+ if (EvdevBitIsSet(pEvdev->rel_bitmask, REL_DIAL))
+ num_axes--;
+
+ if (num_axes <= 0)
+ goto out;
+#endif
+
+ if (num_axes > MAX_VALUATORS) {
+ xf86IDrvMsg(pInfo, X_WARNING, "found %d axes, limiting to %d.\n", num_axes, MAX_VALUATORS);
+ num_axes = MAX_VALUATORS;
+ }
+
+ pEvdev->num_vals = num_axes;
+ if (num_axes > 0) {
+ pEvdev->vals = valuator_mask_new(num_axes);
+ if (!pEvdev->vals)
+ goto out;
+ }
+ atoms = malloc(pEvdev->num_vals * sizeof(Atom));
+
+ for (axis = REL_X; i < MAX_VALUATORS && axis <= REL_MAX; axis++)
+ {
+ pEvdev->axis_map[axis] = -1;
+#ifndef HAVE_SMOOTH_SCROLLING
+ /* We don't post wheel events, so ignore them here too */
+ if (axis == REL_WHEEL || axis == REL_HWHEEL || axis == REL_DIAL)
+ continue;
+#endif
+ if (!EvdevBitIsSet(pEvdev->rel_bitmask, axis))
+ continue;
+ pEvdev->axis_map[axis] = i;
+ i++;
+ }
+
+ EvdevInitAxesLabels(pEvdev, Relative, pEvdev->num_vals, atoms);
+
+ if (!InitValuatorClassDeviceStruct(device, num_axes, atoms,
+ GetMotionHistorySize(), Relative)) {
+ xf86IDrvMsg(pInfo, X_ERROR, "failed to initialize valuator class device.\n");
+ goto out;
+ }
+
+ if (!InitPtrFeedbackClassDeviceStruct(device, EvdevPtrCtrlProc)) {
+ xf86IDrvMsg(pInfo, X_ERROR, "failed to initialize pointer feedback class "
+ "device.\n");
+ goto out;
+ }
+
+ for (axis = REL_X; axis <= REL_MAX; axis++)
+ {
+ int axnum = pEvdev->axis_map[axis];
+
+ if (axnum == -1)
+ continue;
+ xf86InitValuatorAxisStruct(device, axnum, atoms[axnum], -1, -1, 1, 0, 1,
+ Relative);
+ xf86InitValuatorDefaults(device, axnum);
+#ifdef HAVE_SMOOTH_SCROLLING
+ if (axis == REL_WHEEL)
+ SetScrollValuator(device, axnum, SCROLL_TYPE_VERTICAL, -1.0, SCROLL_FLAG_PREFERRED);
+ else if (axis == REL_DIAL)
+ SetScrollValuator(device, axnum, SCROLL_TYPE_VERTICAL, -1.0, SCROLL_FLAG_NONE);
+ else if (axis == REL_HWHEEL)
+ SetScrollValuator(device, axnum, SCROLL_TYPE_HORIZONTAL, 1.0, SCROLL_FLAG_NONE);
+#endif
+ }
+
+ free(atoms);
+
+ return Success;
+
+out:
+ valuator_mask_free(&pEvdev->vals);
+ return !Success;
+}
+
+static int
+EvdevAddButtonClass(DeviceIntPtr device)
+{
+ InputInfoPtr pInfo;
+ EvdevPtr pEvdev;
+ Atom *labels;
+
+ pInfo = device->public.devicePrivate;
+ pEvdev = pInfo->private;
+
+ labels = malloc(pEvdev->num_buttons * sizeof(Atom));
+ EvdevInitButtonLabels(pEvdev, pEvdev->num_buttons, labels);
+
+ if (!InitButtonClassDeviceStruct(device, pEvdev->num_buttons, labels,
+ pEvdev->btnmap))
+ return !Success;
+
+ free(labels);
+ return Success;
+}
+
+/**
+ * Init the button mapping for the device. By default, this is a 1:1 mapping,
+ * i.e. Button 1 maps to Button 1, Button 2 to 2, etc.
+ *
+ * If a mapping has been specified, the mapping is the default, with the
+ * user-defined ones overwriting the defaults.
+ * i.e. a user-defined mapping of "3 2 1" results in a mapping of 3 2 1 4 5 6 ...
+ *
+ * Invalid button mappings revert to the default.
+ *
+ * Note that index 0 is unused, button 0 does not exist.
+ * This mapping is initialised for all devices, but only applied if the device
+ * has buttons (in EvdevAddButtonClass).
+ */
+static void
+EvdevInitButtonMapping(InputInfoPtr pInfo)
+{
+ int i, nbuttons = 1;
+ char *mapping = NULL;
+ EvdevPtr pEvdev = pInfo->private;
+
+ /* Check for user-defined button mapping */
+ if ((mapping = xf86CheckStrOption(pInfo->options, "ButtonMapping", NULL)))
+ {
+ char *map, *s = NULL;
+ int btn = 0;
+
+ xf86IDrvMsg(pInfo, X_CONFIG, "ButtonMapping '%s'\n", mapping);
+ map = mapping;
+ do
+ {
+ btn = strtol(map, &s, 10);
+
+ if (s == map || btn < 0 || btn > EVDEV_MAXBUTTONS)
+ {
+ xf86IDrvMsg(pInfo, X_ERROR,
+ "... Invalid button mapping. Using defaults\n");
+ nbuttons = 1; /* ensure defaults start at 1 */
+ break;
+ }
+
+ pEvdev->btnmap[nbuttons++] = btn;
+ map = s;
+ } while (s && *s != '\0' && nbuttons < EVDEV_MAXBUTTONS);
+ free(mapping);
+ }
+
+ for (i = nbuttons; i < ArrayLength(pEvdev->btnmap); i++)
+ pEvdev->btnmap[i] = i;
+
+}
+
+static void
+EvdevInitAnyValuators(DeviceIntPtr device, EvdevPtr pEvdev)
+{
+ InputInfoPtr pInfo = device->public.devicePrivate;
+
+ if (pEvdev->flags & EVDEV_RELATIVE_EVENTS &&
+ EvdevAddRelValuatorClass(device) == Success)
+ xf86IDrvMsg(pInfo, X_INFO, "initialized for relative axes.\n");
+ if (pEvdev->flags & EVDEV_ABSOLUTE_EVENTS &&
+ EvdevAddAbsValuatorClass(device) == Success)
+ xf86IDrvMsg(pInfo, X_INFO, "initialized for absolute axes.\n");
+}
+
+static void
+EvdevInitAbsValuators(DeviceIntPtr device, EvdevPtr pEvdev)
+{
+ InputInfoPtr pInfo = device->public.devicePrivate;
+
+ if (EvdevAddAbsValuatorClass(device) == Success) {
+ xf86IDrvMsg(pInfo, X_INFO,"initialized for absolute axes.\n");
+ } else {
+ xf86IDrvMsg(pInfo, X_ERROR,"failed to initialize for absolute axes.\n");
+ pEvdev->flags &= ~EVDEV_ABSOLUTE_EVENTS;
+ }
+}
+
+static void
+EvdevInitRelValuators(DeviceIntPtr device, EvdevPtr pEvdev)
+{
+ InputInfoPtr pInfo = device->public.devicePrivate;
+ int has_abs_axes = pEvdev->flags & EVDEV_ABSOLUTE_EVENTS;
+
+ if (EvdevAddRelValuatorClass(device) == Success) {
+
+ xf86IDrvMsg(pInfo, X_INFO,"initialized for relative axes.\n");
+
+ if (has_abs_axes) {
+ xf86IDrvMsg(pInfo, X_WARNING,"ignoring absolute axes.\n");
+ pEvdev->flags &= ~EVDEV_ABSOLUTE_EVENTS;
+ }
+
+ } else {
+ xf86IDrvMsg(pInfo, X_ERROR,"failed to initialize for relative axes.\n");
+
+ pEvdev->flags &= ~EVDEV_RELATIVE_EVENTS;
+
+ if (has_abs_axes)
+ EvdevInitAbsValuators(device, pEvdev);
+ }
+}
+
+static void
+EvdevInitTouchDevice(DeviceIntPtr device, EvdevPtr pEvdev)
+{
+ InputInfoPtr pInfo = device->public.devicePrivate;
+
+ if (pEvdev->flags & EVDEV_RELATIVE_EVENTS) {
+ xf86IDrvMsg(pInfo, X_WARNING, "touchpads, tablets and touchscreens "
+ "ignore relative axes.\n");
+ pEvdev->flags &= ~EVDEV_RELATIVE_EVENTS;
+ }
+
+ EvdevInitAbsValuators(device, pEvdev);
+}
+
+static int
+EvdevInit(DeviceIntPtr device)
+{
+ int i;
+ InputInfoPtr pInfo;
+ EvdevPtr pEvdev;
+
+ pInfo = device->public.devicePrivate;
+ pEvdev = pInfo->private;
+
+ /* clear all axis_map entries */
+ for(i = 0; i < max(ABS_CNT,REL_CNT); i++)
+ pEvdev->axis_map[i]=-1;
+
+ if (pEvdev->flags & EVDEV_KEYBOARD_EVENTS)
+ EvdevAddKeyClass(device);
+ if (pEvdev->flags & EVDEV_BUTTON_EVENTS)
+ EvdevAddButtonClass(device);
+
+ /* We don't allow relative and absolute axes on the same device. The
+ * reason is that some devices (MS Optical Desktop 2000) register both
+ * rel and abs axes for x/y.
+ *
+ * The abs axes register min/max; this min/max then also applies to the
+ * relative device (the mouse) and caps it at 0..255 for both axes.
+ * So, unless you have a small screen, you won't be enjoying it much;
+ * consequently, absolute axes are generally ignored.
+ *
+ * However, currenly only a device with absolute axes can be registered
+ * as a touch{pad,screen}. Thus, given such a device, absolute axes are
+ * used and relative axes are ignored.
+ */
+
+ if (pEvdev->flags & (EVDEV_UNIGNORE_RELATIVE | EVDEV_UNIGNORE_ABSOLUTE))
+ EvdevInitAnyValuators(device, pEvdev);
+ else if (pEvdev->flags & (EVDEV_TOUCHPAD | EVDEV_TOUCHSCREEN | EVDEV_TABLET))
+ EvdevInitTouchDevice(device, pEvdev);
+ else if (pEvdev->flags & EVDEV_RELATIVE_EVENTS)
+ EvdevInitRelValuators(device, pEvdev);
+ else if (pEvdev->flags & EVDEV_ABSOLUTE_EVENTS)
+ EvdevInitAbsValuators(device, pEvdev);
+
+ /* We drop the return value, the only time we ever want the handlers to
+ * unregister is when the device dies. In which case we don't have to
+ * unregister anyway */
+ EvdevInitProperty(device);
+ XIRegisterPropertyHandler(device, EvdevSetProperty, NULL, NULL);
+ EvdevMBEmuInitProperty(device);
+ Evdev3BEmuInitProperty(device);
+ EvdevWheelEmuInitProperty(device);
+ EvdevDragLockInitProperty(device);
+ EvdevAppleInitProperty(device);
+
+ return Success;
+}
+
+/**
+ * Init all extras (wheel emulation, etc.) and grab the device.
+ */
+static int
+EvdevOn(DeviceIntPtr device)
+{
+ InputInfoPtr pInfo;
+ EvdevPtr pEvdev;
+ int rc = Success;
+
+ pInfo = device->public.devicePrivate;
+ pEvdev = pInfo->private;
+ /* after PreInit fd is still open */
+ rc = EvdevOpenDevice(pInfo);
+ if (rc != Success)
+ return rc;
+
+ EvdevGrabDevice(pInfo, 1, 0);
+
+ xf86FlushInput(pInfo->fd);
+ xf86AddEnabledDevice(pInfo);
+ EvdevMBEmuOn(pInfo);
+ Evdev3BEmuOn(pInfo);
+ pEvdev->flags |= EVDEV_INITIALIZED;
+ device->public.on = TRUE;
+
+ return Success;
+}
+
+
+static int
+EvdevProc(DeviceIntPtr device, int what)
+{
+ InputInfoPtr pInfo;
+ EvdevPtr pEvdev;
+
+ pInfo = device->public.devicePrivate;
+ pEvdev = pInfo->private;
+
+ switch (what)
+ {
+ case DEVICE_INIT:
+ return EvdevInit(device);
+
+ case DEVICE_ON:
+ return EvdevOn(device);
+
+ case DEVICE_OFF:
+ if (pEvdev->flags & EVDEV_INITIALIZED)
+ {
+ EvdevMBEmuFinalize(pInfo);
+ Evdev3BEmuFinalize(pInfo);
+ }
+ if (pInfo->fd != -1)
+ {
+ EvdevGrabDevice(pInfo, 0, 1);
+ xf86RemoveEnabledDevice(pInfo);
+ EvdevCloseDevice(pInfo);
+ }
+ pEvdev->min_maj = 0;
+ pEvdev->flags &= ~EVDEV_INITIALIZED;
+ device->public.on = FALSE;
+ break;
+
+ case DEVICE_CLOSE:
+ xf86IDrvMsg(pInfo, X_INFO, "Close\n");
+ EvdevCloseDevice(pInfo);
+ EvdevFreeMasks(pEvdev);
+ EvdevRemoveDevice(pInfo);
+ pEvdev->min_maj = 0;
+ break;
+
+ default:
+ return BadValue;
+ }
+
+ return Success;
+}
+
+/**
+ * Get as much information as we can from the fd and cache it.
+ *
+ * @return Success if the information was cached, or !Success otherwise.
+ */
+static int
+EvdevCache(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ int i, len;
+ struct input_id id;
+
+ char name[1024] = {0};
+ unsigned long bitmask[NLONGS(EV_CNT)] = {0};
+ unsigned long key_bitmask[NLONGS(KEY_CNT)] = {0};
+ unsigned long rel_bitmask[NLONGS(REL_CNT)] = {0};
+ unsigned long abs_bitmask[NLONGS(ABS_CNT)] = {0};
+ unsigned long led_bitmask[NLONGS(LED_CNT)] = {0};
+
+
+ if (ioctl(pInfo->fd, EVIOCGID, &id) < 0)
+ {
+ xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGID failed: %s\n", strerror(errno));
+ goto error;
+ }
+
+ pEvdev->id_vendor = id.vendor;
+ pEvdev->id_product = id.product;
+
+ if (ioctl(pInfo->fd, EVIOCGNAME(sizeof(name) - 1), name) < 0) {
+ xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGNAME failed: %s\n", strerror(errno));
+ goto error;
+ }
+
+ strcpy(pEvdev->name, name);
+
+ len = ioctl(pInfo->fd, EVIOCGBIT(0, sizeof(bitmask)), bitmask);
+ if (len < 0) {
+ xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGBIT failed: %s\n",
+ strerror(errno));
+ goto error;
+ }
+
+ memcpy(pEvdev->bitmask, bitmask, len);
+
+ len = ioctl(pInfo->fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask);
+ if (len < 0) {
+ xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGBIT failed: %s\n",
+ strerror(errno));
+ goto error;
+ }
+
+ memcpy(pEvdev->rel_bitmask, rel_bitmask, len);
+
+ len = ioctl(pInfo->fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask);
+ if (len < 0) {
+ xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGBIT failed: %s\n",
+ strerror(errno));
+ goto error;
+ }
+
+ memcpy(pEvdev->abs_bitmask, abs_bitmask, len);
+
+ len = ioctl(pInfo->fd, EVIOCGBIT(EV_LED, sizeof(led_bitmask)), led_bitmask);
+ if (len < 0) {
+ xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGBIT failed: %s\n",
+ strerror(errno));
+ goto error;
+ }
+
+ memcpy(pEvdev->led_bitmask, led_bitmask, len);
+
+ /*
+ * Do not try to validate absinfo data since it is not expected
+ * to be static, always refresh it in evdev structure.
+ */
+ for (i = ABS_X; i <= ABS_MAX; i++) {
+ if (EvdevBitIsSet(abs_bitmask, i)) {
+ len = ioctl(pInfo->fd, EVIOCGABS(i), &pEvdev->absinfo[i]);
+ if (len < 0) {
+ xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGABSi(%d) failed: %s\n",
+ i, strerror(errno));
+ goto error;
+ }
+ xf86IDrvMsgVerb(pInfo, X_PROBED, 6, "absolute axis %#x [%d..%d]\n",
+ i, pEvdev->absinfo[i].maximum, pEvdev->absinfo[i].minimum);
+ }
+ }
+
+ len = ioctl(pInfo->fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask);
+ if (len < 0) {
+ xf86IDrvMsg(pInfo, X_ERROR, "ioctl EVIOCGBIT failed: %s\n",
+ strerror(errno));
+ goto error;
+ }
+
+ /* Copy the data so we have reasonably up-to-date info */
+ memcpy(pEvdev->key_bitmask, key_bitmask, len);
+
+ return Success;
+
+error:
+ return !Success;
+
+}
+
+/**
+ * Issue an EVIOCGRAB on the device file, either as a grab or to ungrab, or
+ * both. Return TRUE on success, otherwise FALSE. Failing the release is a
+ * still considered a success, because it's not as if you could do anything
+ * about it.
+ */
+static BOOL
+EvdevGrabDevice(InputInfoPtr pInfo, int grab, int ungrab)
+{
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (pEvdev->grabDevice)
+ {
+ if (grab && ioctl(pInfo->fd, EVIOCGRAB, (void *)1)) {
+ xf86IDrvMsg(pInfo, X_WARNING, "Grab failed (%s)\n",
+ strerror(errno));
+ return FALSE;
+ } else if (ungrab && ioctl(pInfo->fd, EVIOCGRAB, (void *)0))
+ xf86IDrvMsg(pInfo, X_WARNING, "Release failed (%s)\n",
+ strerror(errno));
+ }
+
+ return TRUE;
+}
+
+/**
+ * Some devices only have other axes (e.g. wheels), but we
+ * still need x/y for these. The server relies on devices having
+ * x/y as axes 0/1 and core/XI 1.x clients expect it too (#44655)
+ */
+static void
+EvdevForceXY(InputInfoPtr pInfo, int mode)
+{
+ EvdevPtr pEvdev = pInfo->private;
+
+ xf86IDrvMsg(pInfo, X_INFO, "Forcing %s x/y axes to exist.\n",
+ (mode == Relative) ? "relative" : "absolute");
+
+ if (mode == Relative)
+ {
+ EvdevSetBit(pEvdev->rel_bitmask, REL_X);
+ EvdevSetBit(pEvdev->rel_bitmask, REL_Y);
+ } else if (mode == Absolute)
+ {
+ EvdevSetBit(pEvdev->abs_bitmask, ABS_X);
+ EvdevSetBit(pEvdev->abs_bitmask, ABS_Y);
+ pEvdev->absinfo[ABS_X].minimum = 0;
+ pEvdev->absinfo[ABS_X].maximum = 1000;
+ pEvdev->absinfo[ABS_X].value = 0;
+ pEvdev->absinfo[ABS_X].resolution = 0;
+ pEvdev->absinfo[ABS_Y].minimum = 0;
+ pEvdev->absinfo[ABS_Y].maximum = 1000;
+ pEvdev->absinfo[ABS_Y].value = 0;
+ pEvdev->absinfo[ABS_Y].resolution = 0;
+ }
+}
+
+static int
+EvdevProbe(InputInfoPtr pInfo)
+{
+ int i, has_rel_axes, has_abs_axes, has_keys, num_buttons, has_scroll;
+ int has_lmr; /* left middle right */
+ int has_mt; /* multitouch */
+ int ignore_abs = 0, ignore_rel = 0;
+ EvdevPtr pEvdev = pInfo->private;
+ int rc = 1;
+
+ xf86IDrvMsg(pInfo, X_PROBED, "Vendor %#hx Product %#hx\n",
+ pEvdev->id_vendor, pEvdev->id_product);
+
+ /* Trinary state for ignoring axes:
+ - unset: do the normal thing.
+ - TRUE: explicitly ignore them.
+ - FALSE: unignore axes, use them at all cost if they're present.
+ */
+ if (xf86FindOption(pInfo->options, "IgnoreRelativeAxes"))
+ {
+ if (xf86SetBoolOption(pInfo->options, "IgnoreRelativeAxes", FALSE))
+ ignore_rel = TRUE;
+ else
+ pEvdev->flags |= EVDEV_UNIGNORE_RELATIVE;
+
+ }
+ if (xf86FindOption(pInfo->options, "IgnoreAbsoluteAxes"))
+ {
+ if (xf86SetBoolOption(pInfo->options, "IgnoreAbsoluteAxes", FALSE))
+ ignore_abs = TRUE;
+ else
+ pEvdev->flags |= EVDEV_UNIGNORE_ABSOLUTE;
+ }
+
+ has_rel_axes = FALSE;
+ has_abs_axes = FALSE;
+ has_keys = FALSE;
+ has_scroll = FALSE;
+ has_lmr = FALSE;
+ has_mt = FALSE;
+ num_buttons = 0;
+
+ /* count all buttons */
+ for (i = BTN_MISC; i < BTN_JOYSTICK; i++)
+ {
+ int mapping = 0;
+ if (EvdevBitIsSet(pEvdev->key_bitmask, i))
+ {
+ mapping = EvdevUtilButtonEventToButtonNumber(pEvdev, i);
+ if (mapping > num_buttons)
+ num_buttons = mapping;
+ }
+ }
+
+ has_lmr = EvdevBitIsSet(pEvdev->key_bitmask, BTN_LEFT) ||
+ EvdevBitIsSet(pEvdev->key_bitmask, BTN_MIDDLE) ||
+ EvdevBitIsSet(pEvdev->key_bitmask, BTN_RIGHT);
+
+ if (num_buttons)
+ {
+ pEvdev->flags |= EVDEV_BUTTON_EVENTS;
+ pEvdev->num_buttons = num_buttons;
+ xf86IDrvMsg(pInfo, X_PROBED, "Found %d mouse buttons\n", num_buttons);
+ }
+
+ for (i = 0; i < REL_MAX; i++) {
+ if (EvdevBitIsSet(pEvdev->rel_bitmask, i)) {
+ has_rel_axes = TRUE;
+ break;
+ }
+ }
+
+ if (has_rel_axes) {
+ if (EvdevBitIsSet(pEvdev->rel_bitmask, REL_WHEEL) ||
+ EvdevBitIsSet(pEvdev->rel_bitmask, REL_HWHEEL) ||
+ EvdevBitIsSet(pEvdev->rel_bitmask, REL_DIAL)) {
+ xf86IDrvMsg(pInfo, X_PROBED, "Found scroll wheel(s)\n");
+ has_scroll = TRUE;
+ if (!num_buttons)
+ xf86IDrvMsg(pInfo, X_INFO,
+ "Forcing buttons for scroll wheel(s)\n");
+ num_buttons = (num_buttons < 3) ? 7 : num_buttons + 4;
+ pEvdev->num_buttons = num_buttons;
+ }
+
+ if (!ignore_rel)
+ {
+ xf86IDrvMsg(pInfo, X_PROBED, "Found relative axes\n");
+ pEvdev->flags |= EVDEV_RELATIVE_EVENTS;
+
+ if (EvdevBitIsSet(pEvdev->rel_bitmask, REL_X) &&
+ EvdevBitIsSet(pEvdev->rel_bitmask, REL_Y)) {
+ xf86IDrvMsg(pInfo, X_PROBED, "Found x and y relative axes\n");
+ } else if (!EvdevBitIsSet(pEvdev->abs_bitmask, ABS_X) ||
+ !EvdevBitIsSet(pEvdev->abs_bitmask, ABS_Y))
+ EvdevForceXY(pInfo, Relative);
+ } else {
+ xf86IDrvMsg(pInfo, X_INFO, "Relative axes present but ignored.\n");
+ has_rel_axes = FALSE;
+ }
+ }
+
+ for (i = 0; i < ABS_MAX; i++) {
+ if (EvdevBitIsSet(pEvdev->abs_bitmask, i)) {
+ has_abs_axes = TRUE;
+ break;
+ }
+ }
+
+#ifdef MULTITOUCH
+ for (i = ABS_MT_SLOT; i < ABS_MAX; i++) {
+ if (EvdevBitIsSet(pEvdev->abs_bitmask, i)) {
+ has_mt = TRUE;
+ break;
+ }
+ }
+#endif
+
+ if (ignore_abs && has_abs_axes)
+ {
+ xf86IDrvMsg(pInfo, X_INFO, "Absolute axes present but ignored.\n");
+ has_abs_axes = FALSE;
+ } else if (has_abs_axes) {
+ xf86IDrvMsg(pInfo, X_PROBED, "Found absolute axes\n");
+ pEvdev->flags |= EVDEV_ABSOLUTE_EVENTS;
+
+ if (has_mt)
+ xf86IDrvMsg(pInfo, X_PROBED, "Found absolute multitouch axes\n");
+
+ if ((EvdevBitIsSet(pEvdev->abs_bitmask, ABS_X) &&
+ EvdevBitIsSet(pEvdev->abs_bitmask, ABS_Y))) {
+ xf86IDrvMsg(pInfo, X_PROBED, "Found x and y absolute axes\n");
+ if (EvdevBitIsSet(pEvdev->key_bitmask, BTN_TOOL_PEN) ||
+ EvdevBitIsSet(pEvdev->key_bitmask, BTN_STYLUS) ||
+ EvdevBitIsSet(pEvdev->key_bitmask, BTN_STYLUS2))
+ {
+ xf86IDrvMsg(pInfo, X_PROBED, "Found absolute tablet.\n");
+ pEvdev->flags |= EVDEV_TABLET;
+ if (!pEvdev->num_buttons)
+ {
+ pEvdev->num_buttons = 7; /* LMR + scroll wheels */
+ pEvdev->flags |= EVDEV_BUTTON_EVENTS;
+ }
+ } else if (EvdevBitIsSet(pEvdev->abs_bitmask, ABS_PRESSURE) ||
+ EvdevBitIsSet(pEvdev->key_bitmask, BTN_TOUCH)) {
+ if (has_lmr || EvdevBitIsSet(pEvdev->key_bitmask, BTN_TOOL_FINGER)) {
+ xf86IDrvMsg(pInfo, X_PROBED, "Found absolute touchpad.\n");
+ pEvdev->flags |= EVDEV_TOUCHPAD;
+ } else {
+ xf86IDrvMsg(pInfo, X_PROBED, "Found absolute touchscreen\n");
+ pEvdev->flags |= EVDEV_TOUCHSCREEN;
+ pEvdev->flags |= EVDEV_BUTTON_EVENTS;
+ }
+ } else if (!(EvdevBitIsSet(pEvdev->rel_bitmask, REL_X) &&
+ EvdevBitIsSet(pEvdev->rel_bitmask, REL_Y)) && has_lmr) {
+ /* some touchscreens use BTN_LEFT rather than BTN_TOUCH */
+ xf86IDrvMsg(pInfo, X_PROBED, "Found absolute touchscreen\n");
+ pEvdev->flags |= EVDEV_TOUCHSCREEN;
+ pEvdev->flags |= EVDEV_BUTTON_EVENTS;
+ }
+ } else {
+#ifdef MULTITOUCH
+ if (!EvdevBitIsSet(pEvdev->abs_bitmask, ABS_MT_POSITION_X) ||
+ !EvdevBitIsSet(pEvdev->abs_bitmask, ABS_MT_POSITION_Y))
+#endif
+ EvdevForceXY(pInfo, Absolute);
+ }
+
+
+
+ }
+
+ for (i = 0; i < BTN_MISC; i++) {
+ if (EvdevBitIsSet(pEvdev->key_bitmask, i)) {
+ xf86IDrvMsg(pInfo, X_PROBED, "Found keys\n");
+ pEvdev->flags |= EVDEV_KEYBOARD_EVENTS;
+ has_keys = TRUE;
+ break;
+ }
+ }
+
+ if (has_rel_axes || has_abs_axes)
+ {
+ char *str;
+ int num_calibration = 0, calibration[4] = { 0, 0, 0, 0 };
+
+ pEvdev->invert_x = xf86SetBoolOption(pInfo->options, "InvertX", FALSE);
+ pEvdev->invert_y = xf86SetBoolOption(pInfo->options, "InvertY", FALSE);
+ pEvdev->swap_axes = xf86SetBoolOption(pInfo->options, "SwapAxes", FALSE);
+
+ str = xf86CheckStrOption(pInfo->options, "Calibration", NULL);
+ if (str) {
+ num_calibration = sscanf(str, "%d %d %d %d",
+ &calibration[0], &calibration[1],
+ &calibration[2], &calibration[3]);
+ free(str);
+ if (num_calibration == 4)
+ EvdevSetCalibration(pInfo, num_calibration, calibration);
+ else
+ xf86IDrvMsg(pInfo, X_ERROR,
+ "Insufficient calibration factors (%d). Ignoring calibration\n",
+ num_calibration);
+ }
+ }
+
+ if (has_rel_axes || has_abs_axes || num_buttons) {
+ pInfo->flags |= XI86_SEND_DRAG_EVENTS;
+ if (pEvdev->flags & EVDEV_TOUCHPAD) {
+ xf86IDrvMsg(pInfo, X_INFO, "Configuring as touchpad\n");
+ pInfo->type_name = XI_TOUCHPAD;
+ pEvdev->use_proximity = 0;
+ } else if (pEvdev->flags & EVDEV_TABLET) {
+ xf86IDrvMsg(pInfo, X_INFO, "Configuring as tablet\n");
+ pInfo->type_name = XI_TABLET;
+ } else if (pEvdev->flags & EVDEV_TOUCHSCREEN) {
+ xf86IDrvMsg(pInfo, X_INFO, "Configuring as touchscreen\n");
+ pInfo->type_name = XI_TOUCHSCREEN;
+ } else {
+ if (!EvdevBitIsSet(pEvdev->rel_bitmask, REL_X) ||
+ !EvdevBitIsSet(pEvdev->rel_bitmask, REL_Y))
+ EvdevForceXY(pInfo, Relative);
+ xf86IDrvMsg(pInfo, X_INFO, "Configuring as mouse\n");
+ pInfo->type_name = XI_MOUSE;
+ }
+
+ rc = 0;
+ }
+
+ if (has_keys) {
+ xf86IDrvMsg(pInfo, X_INFO, "Configuring as keyboard\n");
+ pInfo->type_name = XI_KEYBOARD;
+ rc = 0;
+ }
+
+ if (has_scroll &&
+ (has_rel_axes || has_abs_axes || num_buttons || has_keys))
+ {
+ xf86IDrvMsg(pInfo, X_INFO, "Adding scrollwheel support\n");
+ pEvdev->flags |= EVDEV_BUTTON_EVENTS;
+ pEvdev->flags |= EVDEV_RELATIVE_EVENTS;
+ }
+
+ if (rc)
+ xf86IDrvMsg(pInfo, X_WARNING, "Don't know how to use device\n");
+
+ return rc;
+}
+
+static void
+EvdevSetCalibration(InputInfoPtr pInfo, int num_calibration, int calibration[4])
+{
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (num_calibration == 0) {
+ pEvdev->flags &= ~EVDEV_CALIBRATED;
+ pEvdev->calibration.min_x = 0;
+ pEvdev->calibration.max_x = 0;
+ pEvdev->calibration.min_y = 0;
+ pEvdev->calibration.max_y = 0;
+ } else if (num_calibration == 4) {
+ pEvdev->flags |= EVDEV_CALIBRATED;
+ pEvdev->calibration.min_x = calibration[0];
+ pEvdev->calibration.max_x = calibration[1];
+ pEvdev->calibration.min_y = calibration[2];
+ pEvdev->calibration.max_y = calibration[3];
+ }
+}
+
+static int
+EvdevOpenDevice(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ char *device = pEvdev->device;
+
+ if (!device)
+ {
+ device = xf86CheckStrOption(pInfo->options, "Device", NULL);
+ if (!device) {
+ xf86IDrvMsg(pInfo, X_ERROR, "No device specified.\n");
+ return BadValue;
+ }
+
+ pEvdev->device = device;
+ xf86IDrvMsg(pInfo, X_CONFIG, "Device: \"%s\"\n", device);
+ }
+
+ if (pInfo->fd < 0)
+ {
+ do {
+ pInfo->fd = open(device, O_RDWR | O_NONBLOCK, 0);
+ } while (pInfo->fd < 0 && errno == EINTR);
+
+ if (pInfo->fd < 0) {
+ xf86IDrvMsg(pInfo, X_ERROR, "Unable to open evdev device \"%s\".\n", device);
+ return BadValue;
+ }
+ }
+
+#ifdef MULTITOUCH
+ if (!pEvdev->mtdev) { /* after PreInit mtdev is still valid */
+ pEvdev->mtdev = mtdev_new_open(pInfo->fd);
+ if (!pEvdev->mtdev) {
+ xf86Msg(X_ERROR, "%s: Couldn't open mtdev device\n", pInfo->name);
+ EvdevCloseDevice(pInfo);
+ return FALSE;
+ }
+ }
+ if (pEvdev->mtdev)
+ pEvdev->cur_slot = pEvdev->mtdev->caps.slot.value;
+#endif
+
+ /* Check major/minor of device node to avoid adding duplicate devices. */
+ pEvdev->min_maj = EvdevGetMajorMinor(pInfo);
+ if (EvdevIsDuplicate(pInfo))
+ {
+ xf86IDrvMsg(pInfo, X_WARNING, "device file is duplicate. Ignoring.\n");
+ EvdevCloseDevice(pInfo);
+ return BadMatch;
+ }
+
+ return Success;
+}
+
+static void
+EvdevCloseDevice(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ if (pInfo->fd >= 0)
+ {
+ close(pInfo->fd);
+ pInfo->fd = -1;
+ }
+
+#ifdef MULTITOUCH
+ if (pEvdev->mtdev)
+ {
+ mtdev_close_delete(pEvdev->mtdev);
+ pEvdev->mtdev = NULL;
+ }
+#endif
+
+}
+
+
+static void
+EvdevUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+{
+ EvdevPtr pEvdev = pInfo ? pInfo->private : NULL;
+ if (pEvdev)
+ {
+ /* Release strings allocated in EvdevAddKeyClass. */
+ XkbFreeRMLVOSet(&pEvdev->rmlvo, FALSE);
+ /* Release string allocated in EvdevOpenDevice. */
+ free(pEvdev->device);
+ pEvdev->device = NULL;
+ }
+ xf86DeleteInput(pInfo, flags);
+}
+
+static int
+EvdevPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+{
+ EvdevPtr pEvdev;
+ int rc = BadAlloc;
+
+ if (!(pEvdev = calloc(sizeof(EvdevRec), 1)))
+ goto error;
+
+ pInfo->private = pEvdev;
+ pInfo->type_name = "UNKNOWN";
+ pInfo->device_control = EvdevProc;
+ pInfo->read_input = EvdevReadInput;
+ pInfo->switch_mode = EvdevSwitchMode;
+
+ rc = EvdevOpenDevice(pInfo);
+ if (rc != Success)
+ goto error;
+
+#ifdef MULTITOUCH
+ pEvdev->cur_slot = -1;
+#endif
+
+ /*
+ * We initialize pEvdev->in_proximity to 1 so that device that doesn't use
+ * proximity will still report events.
+ */
+ pEvdev->in_proximity = 1;
+ pEvdev->use_proximity = 1;
+
+ /* Grabbing the event device stops in-kernel event forwarding. In other
+ words, it disables rfkill and the "Macintosh mouse button emulation".
+ Note that this needs a server that sets the console to RAW mode. */
+ pEvdev->grabDevice = xf86CheckBoolOption(pInfo->options, "GrabDevice", 0);
+
+ /* If grabDevice is set, ungrab immediately since we only want to grab
+ * between DEVICE_ON and DEVICE_OFF. If we never get DEVICE_ON, don't
+ * hold a grab. */
+ if (!EvdevGrabDevice(pInfo, 1, 1))
+ {
+ xf86IDrvMsg(pInfo, X_WARNING, "Device may already be configured.\n");
+ rc = BadMatch;
+ goto error;
+ }
+
+ EvdevInitButtonMapping(pInfo);
+
+ if (EvdevCache(pInfo) || EvdevProbe(pInfo)) {
+ rc = BadMatch;
+ goto error;
+ }
+
+ EvdevAddDevice(pInfo);
+
+ if (pEvdev->flags & EVDEV_BUTTON_EVENTS)
+ {
+ EvdevMBEmuPreInit(pInfo);
+ Evdev3BEmuPreInit(pInfo);
+ EvdevWheelEmuPreInit(pInfo);
+ EvdevDragLockPreInit(pInfo);
+ }
+
+ return Success;
+
+error:
+ EvdevCloseDevice(pInfo);
+ return rc;
+}
+
+_X_EXPORT InputDriverRec EVDEV = {
+ 1,
+ "evdev",
+ NULL,
+ EvdevPreInit,
+ EvdevUnInit,
+ NULL,
+ evdevDefaults
+};
+
+static void
+EvdevUnplug(pointer p)
+{
+}
+
+static pointer
+EvdevPlug(pointer module,
+ pointer options,
+ int *errmaj,
+ int *errmin)
+{
+ xf86AddInputDriver(&EVDEV, module, 0);
+ return module;
+}
+
+static XF86ModuleVersionInfo EvdevVersionRec =
+{
+ "evdev",
+ MODULEVENDORSTRING,
+ MODINFOSTRING1,
+ MODINFOSTRING2,
+ XORG_VERSION_CURRENT,
+ PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
+ ABI_CLASS_XINPUT,
+ ABI_XINPUT_VERSION,
+ MOD_CLASS_XINPUT,
+ {0, 0, 0, 0}
+};
+
+_X_EXPORT XF86ModuleData evdevModuleData =
+{
+ &EvdevVersionRec,
+ EvdevPlug,
+ EvdevUnplug
+};
+
+
+/* Return an index value for a given button event code
+ * returns 0 on non-button event.
+ */
+unsigned int
+EvdevUtilButtonEventToButtonNumber(EvdevPtr pEvdev, int code)
+{
+ switch (code)
+ {
+ /* Mouse buttons */
+ case BTN_LEFT:
+ return 1;
+ case BTN_MIDDLE:
+ return 2;
+ case BTN_RIGHT:
+ return 3;
+ case BTN_SIDE ... BTN_JOYSTICK - 1:
+ return 8 + code - BTN_SIDE;
+
+ /* Generic buttons */
+ case BTN_0 ... BTN_2:
+ return 1 + code - BTN_0;
+ case BTN_3 ... BTN_MOUSE - 1:
+ return 8 + code - BTN_3;
+
+ /* Tablet stylus buttons */
+ case BTN_TOUCH ... BTN_STYLUS2:
+ return 1 + code - BTN_TOUCH;
+
+ /* The rest */
+ default:
+ /* Ignore */
+ return 0;
+ }
+}
+
+/* Aligned with linux/input.h.
+ Note that there are holes in the ABS_ range, these are simply replaced with
+ MISC here */
+static const char *abs_labels[] = {
+ AXIS_LABEL_PROP_ABS_X, /* 0x00 */
+ AXIS_LABEL_PROP_ABS_Y, /* 0x01 */
+ AXIS_LABEL_PROP_ABS_Z, /* 0x02 */
+ AXIS_LABEL_PROP_ABS_RX, /* 0x03 */
+ AXIS_LABEL_PROP_ABS_RY, /* 0x04 */
+ AXIS_LABEL_PROP_ABS_RZ, /* 0x05 */
+ AXIS_LABEL_PROP_ABS_THROTTLE, /* 0x06 */
+ AXIS_LABEL_PROP_ABS_RUDDER, /* 0x07 */
+ AXIS_LABEL_PROP_ABS_WHEEL, /* 0x08 */
+ AXIS_LABEL_PROP_ABS_GAS, /* 0x09 */
+ AXIS_LABEL_PROP_ABS_BRAKE, /* 0x0a */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_HAT0X, /* 0x10 */
+ AXIS_LABEL_PROP_ABS_HAT0Y, /* 0x11 */
+ AXIS_LABEL_PROP_ABS_HAT1X, /* 0x12 */
+ AXIS_LABEL_PROP_ABS_HAT1Y, /* 0x13 */
+ AXIS_LABEL_PROP_ABS_HAT2X, /* 0x14 */
+ AXIS_LABEL_PROP_ABS_HAT2Y, /* 0x15 */
+ AXIS_LABEL_PROP_ABS_HAT3X, /* 0x16 */
+ AXIS_LABEL_PROP_ABS_HAT3Y, /* 0x17 */
+ AXIS_LABEL_PROP_ABS_PRESSURE, /* 0x18 */
+ AXIS_LABEL_PROP_ABS_DISTANCE, /* 0x19 */
+ AXIS_LABEL_PROP_ABS_TILT_X, /* 0x1a */
+ AXIS_LABEL_PROP_ABS_TILT_Y, /* 0x1b */
+ AXIS_LABEL_PROP_ABS_TOOL_WIDTH, /* 0x1c */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_VOLUME /* 0x20 */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MISC, /* undefined */
+ AXIS_LABEL_PROP_ABS_MT_TOUCH_MAJOR, /* 0x30 */
+ AXIS_LABEL_PROP_ABS_MT_TOUCH_MINOR, /* 0x31 */
+ AXIS_LABEL_PROP_ABS_MT_WIDTH_MAJOR, /* 0x32 */
+ AXIS_LABEL_PROP_ABS_MT_WIDTH_MINOR, /* 0x33 */
+ AXIS_LABEL_PROP_ABS_MT_ORIENTATION, /* 0x34 */
+ AXIS_LABEL_PROP_ABS_MT_POSITION_X, /* 0x35 */
+ AXIS_LABEL_PROP_ABS_MT_POSITION_Y, /* 0x36 */
+ AXIS_LABEL_PROP_ABS_MT_TOOL_TYPE, /* 0x37 */
+ AXIS_LABEL_PROP_ABS_MT_BLOB_ID, /* 0x38 */
+ AXIS_LABEL_PROP_ABS_MT_TRACKING_ID, /* 0x39 */
+ AXIS_LABEL_PROP_ABS_MT_PRESSURE, /* 0x3a */
+};
+
+static const char *rel_labels[] = {
+ AXIS_LABEL_PROP_REL_X,
+ AXIS_LABEL_PROP_REL_Y,
+ AXIS_LABEL_PROP_REL_Z,
+ AXIS_LABEL_PROP_REL_RX,
+ AXIS_LABEL_PROP_REL_RY,
+ AXIS_LABEL_PROP_REL_RZ,
+ AXIS_LABEL_PROP_REL_HWHEEL,
+ AXIS_LABEL_PROP_REL_DIAL,
+ AXIS_LABEL_PROP_REL_WHEEL,
+ AXIS_LABEL_PROP_REL_MISC
+};
+
+static const char *btn_labels[][16] = {
+ { /* BTN_MISC group offset 0x100*/
+ BTN_LABEL_PROP_BTN_0, /* 0x00 */
+ BTN_LABEL_PROP_BTN_1, /* 0x01 */
+ BTN_LABEL_PROP_BTN_2, /* 0x02 */
+ BTN_LABEL_PROP_BTN_3, /* 0x03 */
+ BTN_LABEL_PROP_BTN_4, /* 0x04 */
+ BTN_LABEL_PROP_BTN_5, /* 0x05 */
+ BTN_LABEL_PROP_BTN_6, /* 0x06 */
+ BTN_LABEL_PROP_BTN_7, /* 0x07 */
+ BTN_LABEL_PROP_BTN_8, /* 0x08 */
+ BTN_LABEL_PROP_BTN_9 /* 0x09 */
+ },
+ { /* BTN_MOUSE group offset 0x110 */
+ BTN_LABEL_PROP_BTN_LEFT, /* 0x00 */
+ BTN_LABEL_PROP_BTN_RIGHT, /* 0x01 */
+ BTN_LABEL_PROP_BTN_MIDDLE, /* 0x02 */
+ BTN_LABEL_PROP_BTN_SIDE, /* 0x03 */
+ BTN_LABEL_PROP_BTN_EXTRA, /* 0x04 */
+ BTN_LABEL_PROP_BTN_FORWARD, /* 0x05 */
+ BTN_LABEL_PROP_BTN_BACK, /* 0x06 */
+ BTN_LABEL_PROP_BTN_TASK /* 0x07 */
+ },
+ { /* BTN_JOYSTICK group offset 0x120 */
+ BTN_LABEL_PROP_BTN_TRIGGER, /* 0x00 */
+ BTN_LABEL_PROP_BTN_THUMB, /* 0x01 */
+ BTN_LABEL_PROP_BTN_THUMB2, /* 0x02 */
+ BTN_LABEL_PROP_BTN_TOP, /* 0x03 */
+ BTN_LABEL_PROP_BTN_TOP2, /* 0x04 */
+ BTN_LABEL_PROP_BTN_PINKIE, /* 0x05 */
+ BTN_LABEL_PROP_BTN_BASE, /* 0x06 */
+ BTN_LABEL_PROP_BTN_BASE2, /* 0x07 */
+ BTN_LABEL_PROP_BTN_BASE3, /* 0x08 */
+ BTN_LABEL_PROP_BTN_BASE4, /* 0x09 */
+ BTN_LABEL_PROP_BTN_BASE5, /* 0x0a */
+ BTN_LABEL_PROP_BTN_BASE6, /* 0x0b */
+ NULL,
+ NULL,
+ NULL,
+ BTN_LABEL_PROP_BTN_DEAD /* 0x0f */
+ },
+ { /* BTN_GAMEPAD group offset 0x130 */
+ BTN_LABEL_PROP_BTN_A, /* 0x00 */
+ BTN_LABEL_PROP_BTN_B, /* 0x01 */
+ BTN_LABEL_PROP_BTN_C, /* 0x02 */
+ BTN_LABEL_PROP_BTN_X, /* 0x03 */
+ BTN_LABEL_PROP_BTN_Y, /* 0x04 */
+ BTN_LABEL_PROP_BTN_Z, /* 0x05 */
+ BTN_LABEL_PROP_BTN_TL, /* 0x06 */
+ BTN_LABEL_PROP_BTN_TR, /* 0x07 */
+ BTN_LABEL_PROP_BTN_TL2, /* 0x08 */
+ BTN_LABEL_PROP_BTN_TR2, /* 0x09 */
+ BTN_LABEL_PROP_BTN_SELECT, /* 0x0a */
+ BTN_LABEL_PROP_BTN_START, /* 0x0b */
+ BTN_LABEL_PROP_BTN_MODE, /* 0x0c */
+ BTN_LABEL_PROP_BTN_THUMBL, /* 0x0d */
+ BTN_LABEL_PROP_BTN_THUMBR /* 0x0e */
+ },
+ { /* BTN_DIGI group offset 0x140 */
+ BTN_LABEL_PROP_BTN_TOOL_PEN, /* 0x00 */
+ BTN_LABEL_PROP_BTN_TOOL_RUBBER, /* 0x01 */
+ BTN_LABEL_PROP_BTN_TOOL_BRUSH, /* 0x02 */
+ BTN_LABEL_PROP_BTN_TOOL_PENCIL, /* 0x03 */
+ BTN_LABEL_PROP_BTN_TOOL_AIRBRUSH, /* 0x04 */
+ BTN_LABEL_PROP_BTN_TOOL_FINGER, /* 0x05 */
+ BTN_LABEL_PROP_BTN_TOOL_MOUSE, /* 0x06 */
+ BTN_LABEL_PROP_BTN_TOOL_LENS, /* 0x07 */
+ NULL,
+ NULL,
+ BTN_LABEL_PROP_BTN_TOUCH, /* 0x0a */
+ BTN_LABEL_PROP_BTN_STYLUS, /* 0x0b */
+ BTN_LABEL_PROP_BTN_STYLUS2, /* 0x0c */
+ BTN_LABEL_PROP_BTN_TOOL_DOUBLETAP, /* 0x0d */
+ BTN_LABEL_PROP_BTN_TOOL_TRIPLETAP /* 0x0e */
+ },
+ { /* BTN_WHEEL group offset 0x150 */
+ BTN_LABEL_PROP_BTN_GEAR_DOWN, /* 0x00 */
+ BTN_LABEL_PROP_BTN_GEAR_UP /* 0x01 */
+ }
+};
+
+static void EvdevInitAxesLabels(EvdevPtr pEvdev, int mode, int natoms, Atom *atoms)
+{
+ Atom atom;
+ int axis;
+ const char **labels;
+ int labels_len = 0;
+
+ if (mode == Absolute)
+ {
+ labels = abs_labels;
+ labels_len = ArrayLength(abs_labels);
+ } else if (mode == Relative)
+ {
+ labels = rel_labels;
+ labels_len = ArrayLength(rel_labels);
+ } else
+ return;
+
+ memset(atoms, 0, natoms * sizeof(Atom));
+
+ /* Now fill the ones we know */
+ for (axis = 0; axis < labels_len; axis++)
+ {
+ if (pEvdev->axis_map[axis] == -1)
+ continue;
+
+ atom = XIGetKnownProperty(labels[axis]);
+ if (!atom) /* Should not happen */
+ continue;
+
+ atoms[pEvdev->axis_map[axis]] = atom;
+ }
+}
+
+static void EvdevInitButtonLabels(EvdevPtr pEvdev, int natoms, Atom *atoms)
+{
+ Atom atom;
+ int button, bmap;
+
+ /* First, make sure all atoms are initialized */
+ atom = XIGetKnownProperty(BTN_LABEL_PROP_BTN_UNKNOWN);
+ for (button = 0; button < natoms; button++)
+ atoms[button] = atom;
+
+ for (button = BTN_MISC; button < BTN_JOYSTICK; button++)
+ {
+ if (EvdevBitIsSet(pEvdev->key_bitmask, button))
+ {
+ int group = (button % 0x100)/16;
+ int idx = button - ((button/16) * 16);
+
+ if (!btn_labels[group][idx])
+ continue;
+
+ atom = XIGetKnownProperty(btn_labels[group][idx]);
+ if (!atom)
+ continue;
+
+ /* Props are 0-indexed, button numbers start with 1 */
+ bmap = EvdevUtilButtonEventToButtonNumber(pEvdev, button) - 1;
+ atoms[bmap] = atom;
+ }
+ }
+
+ /* wheel buttons, hardcoded anyway */
+ if (natoms > 3)
+ atoms[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+ if (natoms > 4)
+ atoms[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+ if (natoms > 5)
+ atoms[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
+ if (natoms > 6)
+ atoms[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
+}
+
+static void
+EvdevInitProperty(DeviceIntPtr dev)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+ int rc;
+ char *device_node;
+
+ CARD32 product[2];
+
+ prop_product_id = MakeAtom(XI_PROP_PRODUCT_ID, strlen(XI_PROP_PRODUCT_ID), TRUE);
+ product[0] = pEvdev->id_vendor;
+ product[1] = pEvdev->id_product;
+ rc = XIChangeDeviceProperty(dev, prop_product_id, XA_INTEGER, 32,
+ PropModeReplace, 2, product, FALSE);
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_product_id, FALSE);
+
+ /* Device node property */
+ device_node = strdup(pEvdev->device);
+ prop_device = MakeAtom(XI_PROP_DEVICE_NODE,
+ strlen(XI_PROP_DEVICE_NODE), TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_device, XA_STRING, 8,
+ PropModeReplace,
+ strlen(device_node), device_node,
+ FALSE);
+ free(device_node);
+
+ if (rc != Success)
+ return;
+
+ if (EvdevDeviceIsVirtual(pEvdev->device))
+ {
+ BOOL virtual = 1;
+ prop_virtual = MakeAtom(XI_PROP_VIRTUAL_DEVICE,
+ strlen(XI_PROP_VIRTUAL_DEVICE), TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_virtual, XA_INTEGER, 8,
+ PropModeReplace, 1, &virtual, FALSE);
+ XISetDevicePropertyDeletable(dev, prop_virtual, FALSE);
+ }
+
+
+ XISetDevicePropertyDeletable(dev, prop_device, FALSE);
+
+ if (pEvdev->flags & (EVDEV_RELATIVE_EVENTS | EVDEV_ABSOLUTE_EVENTS))
+ {
+ BOOL invert[2];
+ invert[0] = pEvdev->invert_x;
+ invert[1] = pEvdev->invert_y;
+
+ prop_invert = MakeAtom(EVDEV_PROP_INVERT_AXES, strlen(EVDEV_PROP_INVERT_AXES), TRUE);
+
+ rc = XIChangeDeviceProperty(dev, prop_invert, XA_INTEGER, 8,
+ PropModeReplace, 2,
+ invert, FALSE);
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_invert, FALSE);
+
+ prop_calibration = MakeAtom(EVDEV_PROP_CALIBRATION,
+ strlen(EVDEV_PROP_CALIBRATION), TRUE);
+ if (pEvdev->flags & EVDEV_CALIBRATED) {
+ int calibration[4];
+
+ calibration[0] = pEvdev->calibration.min_x;
+ calibration[1] = pEvdev->calibration.max_x;
+ calibration[2] = pEvdev->calibration.min_y;
+ calibration[3] = pEvdev->calibration.max_y;
+
+ rc = XIChangeDeviceProperty(dev, prop_calibration, XA_INTEGER,
+ 32, PropModeReplace, 4, calibration,
+ FALSE);
+ } else if (pEvdev->flags & EVDEV_ABSOLUTE_EVENTS) {
+ rc = XIChangeDeviceProperty(dev, prop_calibration, XA_INTEGER,
+ 32, PropModeReplace, 0, NULL,
+ FALSE);
+ }
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_calibration, FALSE);
+
+ prop_swap = MakeAtom(EVDEV_PROP_SWAP_AXES,
+ strlen(EVDEV_PROP_SWAP_AXES), TRUE);
+
+ rc = XIChangeDeviceProperty(dev, prop_swap, XA_INTEGER, 8,
+ PropModeReplace, 1, &pEvdev->swap_axes, FALSE);
+ if (rc != Success)
+ return;
+
+ XISetDevicePropertyDeletable(dev, prop_swap, FALSE);
+
+ /* Axis labelling */
+ if ((pEvdev->num_vals > 0) && (prop_axis_label = XIGetKnownProperty(AXIS_LABEL_PROP)))
+ {
+ int mode;
+ int num_axes = pEvdev->num_vals + pEvdev->num_mt_vals;
+ Atom atoms[num_axes];
+
+ if (pEvdev->flags & EVDEV_ABSOLUTE_EVENTS)
+ mode = Absolute;
+ else if (pEvdev->flags & EVDEV_RELATIVE_EVENTS)
+ mode = Relative;
+ else {
+ xf86IDrvMsg(pInfo, X_ERROR, "BUG: mode is neither absolute nor relative\n");
+ mode = Absolute;
+ }
+
+ EvdevInitAxesLabels(pEvdev, mode, num_axes, atoms);
+ XIChangeDeviceProperty(dev, prop_axis_label, XA_ATOM, 32,
+ PropModeReplace, num_axes, atoms, FALSE);
+ XISetDevicePropertyDeletable(dev, prop_axis_label, FALSE);
+ }
+ /* Button labelling */
+ if ((pEvdev->num_buttons > 0) && (prop_btn_label = XIGetKnownProperty(BTN_LABEL_PROP)))
+ {
+ Atom atoms[EVDEV_MAXBUTTONS];
+ EvdevInitButtonLabels(pEvdev, EVDEV_MAXBUTTONS, atoms);
+ XIChangeDeviceProperty(dev, prop_btn_label, XA_ATOM, 32,
+ PropModeReplace, pEvdev->num_buttons, atoms, FALSE);
+ XISetDevicePropertyDeletable(dev, prop_btn_label, FALSE);
+ }
+ }
+
+}
+
+static int
+EvdevSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
+ BOOL checkonly)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ EvdevPtr pEvdev = pInfo->private;
+
+ if (atom == prop_invert)
+ {
+ BOOL* data;
+ if (val->format != 8 || val->size != 2 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ if (!checkonly)
+ {
+ data = (BOOL*)val->data;
+ pEvdev->invert_x = data[0];
+ pEvdev->invert_y = data[1];
+ }
+ } else if (atom == prop_calibration)
+ {
+ if (val->format != 32 || val->type != XA_INTEGER)
+ return BadMatch;
+ if (val->size != 4 && val->size != 0)
+ return BadMatch;
+
+ if (!checkonly)
+ EvdevSetCalibration(pInfo, val->size, val->data);
+ } else if (atom == prop_swap)
+ {
+ if (val->format != 8 || val->type != XA_INTEGER || val->size != 1)
+ return BadMatch;
+
+ if (!checkonly)
+ pEvdev->swap_axes = *((BOOL*)val->data);
+ } else if (atom == prop_axis_label || atom == prop_btn_label ||
+ atom == prop_product_id || atom == prop_device ||
+ atom == prop_virtual)
+ return BadAccess; /* Read-only properties */
+
+ return Success;
+}
diff --git a/src/evdev.h b/src/evdev.h
new file mode 100644
index 0000000..c2f9246
--- /dev/null
+++ b/src/evdev.h
@@ -0,0 +1,302 @@
+/*
+ * Copyright © 2004-2008 Red Hat, Inc.
+ * 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 Red Hat
+ * not be used in advertising or publicity pertaining to distribution
+ * of the software without specific, written prior permission. Red
+ * Hat makes 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.
+ *
+ * Authors:
+ * Kristian Høgsberg (krh@redhat.com)
+ * Adam Jackson (ajax@redhat.com)
+ * Peter Hutterer (peter@cs.unisa.edu.au)
+ * Oliver McFadden (oliver.mcfadden@nokia.com)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef EVDEV_H
+#define EVDEV_H
+
+#include <linux/input.h>
+#include <linux/types.h>
+
+#include <xorg-server.h>
+#include <xf86Xinput.h>
+#include <xf86_OSproc.h>
+#include <xkbstr.h>
+
+#ifdef MULTITOUCH
+#include <mtdev.h>
+#endif
+
+#ifndef EV_CNT /* linux 2.6.23 kernels and earlier lack _CNT defines */
+#define EV_CNT (EV_MAX+1)
+#endif
+#ifndef KEY_CNT
+#define KEY_CNT (KEY_MAX+1)
+#endif
+#ifndef REL_CNT
+#define REL_CNT (REL_MAX+1)
+#endif
+#ifndef ABS_CNT
+#define ABS_CNT (ABS_MAX+1)
+#endif
+#ifndef LED_CNT
+#define LED_CNT (LED_MAX+1)
+#endif
+
+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 14
+#define HAVE_SMOOTH_SCROLLING 1
+#endif
+
+#define EVDEV_MAXBUTTONS 32
+#define EVDEV_MAXQUEUE 32
+
+/* evdev flags */
+#define EVDEV_KEYBOARD_EVENTS (1 << 0)
+#define EVDEV_BUTTON_EVENTS (1 << 1)
+#define EVDEV_RELATIVE_EVENTS (1 << 2)
+#define EVDEV_ABSOLUTE_EVENTS (1 << 3)
+#define EVDEV_TOUCHPAD (1 << 4)
+#define EVDEV_INITIALIZED (1 << 5) /* WheelInit etc. called already? */
+#define EVDEV_TOUCHSCREEN (1 << 6)
+#define EVDEV_CALIBRATED (1 << 7) /* run-time calibrated? */
+#define EVDEV_TABLET (1 << 8) /* device looks like a tablet? */
+#define EVDEV_UNIGNORE_ABSOLUTE (1 << 9) /* explicitly unignore abs axes */
+#define EVDEV_UNIGNORE_RELATIVE (1 << 10) /* explicitly unignore rel axes */
+#define EVDEV_RELATIVE_MODE (1 << 11) /* Force relative events for devices with absolute axes */
+
+#ifndef MAX_VALUATORS
+#define MAX_VALUATORS 36
+#endif
+
+#ifndef XI_PROP_DEVICE_NODE
+#define XI_PROP_DEVICE_NODE "Device Node"
+#endif
+
+#define LONG_BITS (sizeof(long) * 8)
+
+/* Number of longs needed to hold the given number of bits */
+#define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
+
+/* Function key mode */
+enum fkeymode {
+ FKEYMODE_UNKNOWN = 0,
+ FKEYMODE_FKEYS, /* function keys send function keys */
+ FKEYMODE_MMKEYS, /* function keys send multimedia keys */
+};
+
+enum SlotState {
+ SLOTSTATE_OPEN = 8,
+ SLOTSTATE_CLOSE,
+ SLOTSTATE_UPDATE,
+ SLOTSTATE_EMPTY,
+};
+
+enum ButtonAction {
+ BUTTON_RELEASE = 0,
+ BUTTON_PRESS = 1
+};
+
+/* axis specific data for wheel emulation */
+typedef struct {
+ int up_button;
+ int down_button;
+ int traveled_distance;
+} WheelAxis, *WheelAxisPtr;
+
+/* Event queue used to defer keyboard/button events until EV_SYN time. */
+typedef struct {
+ enum {
+ EV_QUEUE_KEY, /* xf86PostKeyboardEvent() */
+ EV_QUEUE_BTN, /* xf86PostButtonEvent() */
+ EV_QUEUE_PROXIMITY, /* xf86PostProximityEvent() */
+#ifdef MULTITOUCH
+ EV_QUEUE_TOUCH, /*xf86PostTouchEvent() */
+#endif
+ } type;
+ union {
+ int key; /* May be either a key code or button number. */
+#ifdef MULTITOUCH
+ unsigned int touch; /* Touch ID */
+#endif
+ } detail;
+ int val; /* State of the key/button/touch; pressed or released. */
+#ifdef MULTITOUCH
+ ValuatorMask *touchMask;
+#endif
+} EventQueueRec, *EventQueuePtr;
+
+typedef struct {
+ unsigned short id_vendor;
+ unsigned short id_product;
+
+ char *device;
+ int grabDevice; /* grab the event device? */
+
+ int num_vals; /* number of valuators */
+ int num_mt_vals; /* number of multitouch valuators */
+ int axis_map[max(ABS_CNT, REL_CNT)]; /* Map evdev <axis> to index */
+ ValuatorMask *vals; /* new values coming in */
+ ValuatorMask *old_vals; /* old values for calculating relative motion */
+ ValuatorMask *prox; /* last values set while not in proximity */
+ ValuatorMask *mt_mask;
+ ValuatorMask **last_mt_vals;
+ int cur_slot;
+ enum SlotState slot_state;
+#ifdef MULTITOUCH
+ struct mtdev *mtdev;
+#endif
+
+ int flags;
+ int in_proximity; /* device in proximity */
+ int use_proximity; /* using the proximity bit? */
+ int num_buttons; /* number of buttons */
+ BOOL swap_axes;
+ BOOL invert_x;
+ BOOL invert_y;
+
+ int delta[REL_CNT];
+ unsigned int abs_queued, rel_queued, prox_queued;
+
+ /* XKB stuff has to be per-device rather than per-driver */
+ XkbRMLVOSet rmlvo;
+
+ /* Middle mouse button emulation */
+ struct {
+ BOOL enabled;
+ BOOL pending; /* timer waiting? */
+ int buttonstate; /* phys. button state */
+ int state; /* state machine (see bt3emu.c) */
+ Time expires; /* time of expiry */
+ Time timeout;
+ } emulateMB;
+ /* Third mouse button emulation */
+ struct emulate3B {
+ BOOL enabled;
+ BOOL state; /* current state */
+ Time timeout; /* timeout until third button press */
+ int buttonstate; /* phys. button state */
+ int button; /* phys button to emit */
+ int threshold; /* move threshold in dev coords */
+ OsTimerPtr timer;
+ int delta[2]; /* delta x/y, accumulating */
+ int startpos[2]; /* starting pos for abs devices */
+ int flags; /* remember if we had rel or abs movement */
+ } emulate3B;
+ struct {
+ int meta; /* meta key to lock any button */
+ BOOL meta_state; /* meta_button state */
+ unsigned int lock_pair[EVDEV_MAXBUTTONS]; /* specify a meta/lock pair */
+ BOOL lock_state[EVDEV_MAXBUTTONS]; /* state of any locked buttons */
+ } dragLock;
+ struct {
+ BOOL enabled;
+ int button;
+ int button_state;
+ int inertia;
+ WheelAxis X;
+ WheelAxis Y;
+ Time expires; /* time of expiry */
+ Time timeout;
+ } emulateWheel;
+ /* run-time calibration */
+ struct {
+ int min_x;
+ int max_x;
+ int min_y;
+ int max_y;
+ } calibration;
+
+ unsigned char btnmap[32]; /* config-file specified button mapping */
+
+ int reopen_attempts; /* max attempts to re-open after read failure */
+ int reopen_left; /* number of attempts left to re-open the device */
+ OsTimerPtr reopen_timer;
+
+ /* Cached info from device. */
+ char name[1024];
+ unsigned long bitmask[NLONGS(EV_CNT)];
+ unsigned long key_bitmask[NLONGS(KEY_CNT)];
+ unsigned long rel_bitmask[NLONGS(REL_CNT)];
+ unsigned long abs_bitmask[NLONGS(ABS_CNT)];
+ unsigned long led_bitmask[NLONGS(LED_CNT)];
+ struct input_absinfo absinfo[ABS_CNT];
+
+ /* minor/major number */
+ dev_t min_maj;
+
+ /* Event queue used to defer keyboard/button events until EV_SYN time. */
+ int num_queue;
+ EventQueueRec queue[EVDEV_MAXQUEUE];
+
+ enum fkeymode fkeymode;
+} EvdevRec, *EvdevPtr;
+
+/* Event posting functions */
+void EvdevQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value);
+void EvdevQueueButtonEvent(InputInfoPtr pInfo, int button, int value);
+void EvdevQueueProximityEvent(InputInfoPtr pInfo, int value);
+#ifdef MULTITOUCH
+void EvdevQueueTouchEvent(InputInfoPtr pInfo, unsigned int touch,
+ ValuatorMask *mask, uint16_t type);
+#endif
+void EvdevPostButtonEvent(InputInfoPtr pInfo, int button, enum ButtonAction act);
+void EvdevQueueButtonClicks(InputInfoPtr pInfo, int button, int count);
+void EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int num_v, int first_v,
+ int v[MAX_VALUATORS]);
+void EvdevPostAbsoluteMotionEvents(InputInfoPtr pInfo, int num_v, int first_v,
+ int v[MAX_VALUATORS]);
+unsigned int EvdevUtilButtonEventToButtonNumber(EvdevPtr pEvdev, int code);
+
+/* Middle Button emulation */
+int EvdevMBEmuTimer(InputInfoPtr);
+BOOL EvdevMBEmuFilterEvent(InputInfoPtr, int, BOOL);
+void EvdevMBEmuWakeupHandler(pointer, int, pointer);
+void EvdevMBEmuBlockHandler(pointer, struct timeval**, pointer);
+void EvdevMBEmuPreInit(InputInfoPtr);
+void EvdevMBEmuOn(InputInfoPtr);
+void EvdevMBEmuFinalize(InputInfoPtr);
+
+/* Third button emulation */
+CARD32 Evdev3BEmuTimer(OsTimerPtr timer, CARD32 time, pointer arg);
+BOOL Evdev3BEmuFilterEvent(InputInfoPtr, int, BOOL);
+void Evdev3BEmuPreInit(InputInfoPtr pInfo);
+void Evdev3BEmuOn(InputInfoPtr);
+void Evdev3BEmuFinalize(InputInfoPtr);
+void Evdev3BEmuProcessRelMotion(InputInfoPtr pInfo, int dx, int dy);
+void Evdev3BEmuProcessAbsMotion(InputInfoPtr pInfo, ValuatorMask *vals);
+
+/* Mouse Wheel emulation */
+void EvdevWheelEmuPreInit(InputInfoPtr pInfo);
+BOOL EvdevWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value);
+BOOL EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv);
+
+/* Draglock code */
+void EvdevDragLockPreInit(InputInfoPtr pInfo);
+BOOL EvdevDragLockFilterEvent(InputInfoPtr pInfo, unsigned int button, int value);
+
+void EvdevMBEmuInitProperty(DeviceIntPtr);
+void Evdev3BEmuInitProperty(DeviceIntPtr);
+void EvdevWheelEmuInitProperty(DeviceIntPtr);
+void EvdevDragLockInitProperty(DeviceIntPtr);
+void EvdevAppleInitProperty(DeviceIntPtr);
+#endif