wsmoused: support absolute mouse position events

Tested with VirtualBox Guest Addtions.
This commit is contained in:
uwe 2021-11-24 14:34:51 +00:00
parent 47ed2bf4a1
commit f9113856a8
3 changed files with 71 additions and 9 deletions

View File

@ -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_event evt)
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:

View File

@ -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

View File

@ -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 {