Module Name: src
Committed By: uwe
Date: Wed Nov 24 14:34:51 UTC 2021
Modified Files:
src/usr.sbin/wsmoused: selection.c wsmoused.c wsmoused.h
Log Message:
wsmoused: support absolute mouse position events
Tested with VirtualBox Guest Addtions.
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/wsmoused/selection.c
cvs rdiff -u -r1.27 -r1.28 src/usr.sbin/wsmoused/wsmoused.c
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/wsmoused/wsmoused.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/wsmoused/selection.c
diff -u src/usr.sbin/wsmoused/selection.c:1.10 src/usr.sbin/wsmoused/selection.c:1.11
--- src/usr.sbin/wsmoused/selection.c:1.10 Sun May 27 15:05:00 2007
+++ src/usr.sbin/wsmoused/selection.c Wed Nov 24 14:34:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: selection.c,v 1.10 2007/05/27 15:05:00 jmmv Exp $ */
+/* $NetBSD: selection.c,v 1.11 2021/11/24 14:34:51 uwe Exp $ */
/*
* Copyright (c) 2002, 2003, 2004, 2007 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: selection.c,v 1.10 2007/05/27 15:05:00 jmmv Exp $");
+__RCSID("$NetBSD: selection.c,v 1.11 2021/11/24 14:34:51 uwe Exp $");
#endif /* not lint */
#include <sys/ioctl.h>
@@ -226,6 +226,7 @@ selection_cleanup(void)
void
selection_wsmouse_event(struct wscons_event evt)
{
+ const struct wsmouse_calibcoords *abs = &Selmouse.sm_mouse->m_calib;
if (IS_MOTION_EVENT(evt.type)) {
if (Selmouse.sm_selecting)
@@ -259,7 +260,30 @@ selection_wsmouse_event(struct wscons_ev
Selmouse.sm_count_y++;
break;
- case WSCONS_EVENT_MOUSE_DELTA_Z:
+ case WSCONS_EVENT_MOUSE_DELTA_Z: /* FALLTHROUGH */
+ case WSCONS_EVENT_MOUSE_DELTA_W:
+ break;
+
+ case WSCONS_EVENT_MOUSE_ABSOLUTE_X:
+ if (!Selmouse.sm_mouse->m_doabs)
+ break;
+ /* max x is inclusive in both selmouse and tpcalib */
+ Selmouse.sm_x
+ = ((evt.value - abs->minx) * (Selmouse.sm_max_x + 1))
+ / (abs->maxx - abs->minx + 1);
+ break;
+
+ case WSCONS_EVENT_MOUSE_ABSOLUTE_Y:
+ if (!Selmouse.sm_mouse->m_doabs)
+ break;
+ /* max y is inclusive in both selmouse and tpcalib */
+ Selmouse.sm_y
+ = ((evt.value - abs->miny) * (Selmouse.sm_max_y + 1))
+ / (abs->maxy - abs->miny + 1);
+ break;
+
+ case WSCONS_EVENT_MOUSE_ABSOLUTE_Z: /* FALLTHROUGH */
+ case WSCONS_EVENT_MOUSE_ABSOLUTE_W:
break;
default:
Index: src/usr.sbin/wsmoused/wsmoused.c
diff -u src/usr.sbin/wsmoused/wsmoused.c:1.27 src/usr.sbin/wsmoused/wsmoused.c:1.28
--- src/usr.sbin/wsmoused/wsmoused.c:1.27 Wed Sep 1 06:10:06 2021
+++ src/usr.sbin/wsmoused/wsmoused.c Wed Nov 24 14:34:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: wsmoused.c,v 1.27 2021/09/01 06:10:06 mlelstv Exp $ */
+/* $NetBSD: wsmoused.c,v 1.28 2021/11/24 14:34:51 uwe Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 2002, 2003\
The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: wsmoused.c,v 1.27 2021/09/01 06:10:06 mlelstv Exp $");
+__RCSID("$NetBSD: wsmoused.c,v 1.28 2021/11/24 14:34:51 uwe Exp $");
#endif /* not lint */
#include <sys/ioctl.h>
@@ -250,7 +250,7 @@ init_mouse(void)
static void
open_device(unsigned int secs)
{
- int version = WSMOUSE_EVENT_VERSION;
+ int status;
if (Mouse.m_devfd != -1)
return;
@@ -262,10 +262,38 @@ open_device(unsigned int secs)
if (Mouse.m_devfd == -1)
log_err(EXIT_FAILURE, "cannot open %s", Mouse.m_devname);
- if (ioctl(Mouse.m_devfd, WSMOUSEIO_SETVERSION, &version) == -1)
+ const int version = WSMOUSE_EVENT_VERSION;
+ status = ioctl(Mouse.m_devfd, WSMOUSEIO_SETVERSION, &version);
+ if (status == -1)
log_err(EXIT_FAILURE, "cannot set version %s", Mouse.m_devname);
+
+
+ /*
+ * Get calibration data for touch panel. Not fatal if we can't.
+ */
+ Mouse.m_doabs = 0;
+
+ unsigned int mouse_type = 0; /* defined WSMOUSE_TYPE_* start at 1 */
+ status = ioctl(Mouse.m_devfd, WSMOUSEIO_GTYPE, &mouse_type);
+ if (status == -1) {
+ log_warn("WSMOUSEIO_GTYPE");
+ return;
+ }
+
+ /* absolute position events make no sense for free-ranging mice */
+ if (mouse_type != WSMOUSE_TYPE_TPANEL)
+ return;
+
+ status = ioctl(Mouse.m_devfd, WSMOUSEIO_GCALIBCOORDS, &Mouse.m_calib);
+ if (status == -1) {
+ log_warn("WSMOUSEIO_GCALIBCOORDS");
+ return;
+ }
+
+ Mouse.m_doabs = 1;
}
+
/* --------------------------------------------------------------------- */
/* Main program event loop. This function polls the wscons status
Index: src/usr.sbin/wsmoused/wsmoused.h
diff -u src/usr.sbin/wsmoused/wsmoused.h:1.9 src/usr.sbin/wsmoused/wsmoused.h:1.10
--- src/usr.sbin/wsmoused/wsmoused.h:1.9 Sat Mar 18 02:06:38 2006
+++ src/usr.sbin/wsmoused/wsmoused.h Wed Nov 24 14:34:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: wsmoused.h,v 1.9 2006/03/18 02:06:38 elad Exp $ */
+/* $NetBSD: wsmoused.h,v 1.10 2021/11/24 14:34:51 uwe Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -34,7 +34,13 @@
#define IS_MOTION_EVENT(type) (((type) == WSCONS_EVENT_MOUSE_DELTA_X) || \
((type) == WSCONS_EVENT_MOUSE_DELTA_Y) || \
- ((type) == WSCONS_EVENT_MOUSE_DELTA_Z))
+ ((type) == WSCONS_EVENT_MOUSE_DELTA_Z) || \
+ ((type) == WSCONS_EVENT_MOUSE_DELTA_W) || \
+ ((type) == WSCONS_EVENT_MOUSE_ABSOLUTE_X) || \
+ ((type) == WSCONS_EVENT_MOUSE_ABSOLUTE_Y) || \
+ ((type) == WSCONS_EVENT_MOUSE_ABSOLUTE_Z) || \
+ ((type) == WSCONS_EVENT_MOUSE_ABSOLUTE_W))
+
#define IS_BUTTON_EVENT(type) (((type) == WSCONS_EVENT_MOUSE_UP) || \
((type) == WSCONS_EVENT_MOUSE_DOWN))
@@ -45,6 +51,10 @@ struct mouse {
char *m_devname; /* File name of wsmouse device */
char *m_fifoname; /* File name of fifo */
int m_disabled; /* Whether if the mouse is disabled or not */
+
+ /* support for absolute position events */
+ int m_doabs;
+ struct wsmouse_calibcoords m_calib;
};
struct mode_bootstrap {