Fixed bug 5461 - Add rewritten WSCONS driver for OpenBSD

wahil1976

This patch adds a written-from-scratch WSCONS driver for OpenBSD. It does not have hardcoded keymaps, and it features mouse support when wsmux is available.

For this to work, it needs access to the /dev/wskbd* devices which are not available to non-root users by default. Access to those can be granted by changing /etc/fbtab to give the logging user the ownership of those devices.
This commit is contained in:
Sam Lantinga
2021-01-14 14:32:11 -08:00
parent 1adadc7702
commit 82aafa9aa8
7 changed files with 1017 additions and 0 deletions
+32
View File
@@ -2679,6 +2679,30 @@ CheckInputKBIO()
fi
}
dnl See if we can use the wscons input driver
CheckInputWSCONS()
{
AC_MSG_CHECKING(for OpenBSD wscons)
use_input_wscons=no
AC_TRY_COMPILE([
#include <sys/time.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsksymdef.h>
#include <dev/wscons/wsksymvar.h>
#include <sys/ioctl.h>
],[
struct wskbd_map_data data;
ioctl(0, WSKBDIO_GETMAP, &data);
],[
use_input_wscons=yes
])
AC_MSG_RESULT($use_input_wscons)
if test x$use_input_wscons = xyes; then
AC_DEFINE(SDL_INPUT_WSCONS, 1, [ ])
SUMMARY_input="${SUMMARY_input} wscons"
fi
}
dnl See if the platform offers libudev for device enumeration and hotplugging.
CheckLibUDev()
{
@@ -3596,6 +3620,9 @@ case "$host" in
freebsd)
CheckInputKBIO
;;
openbsd)
CheckInputWSCONS
;;
esac
CheckUSBHID
CheckHIDAPI
@@ -3741,6 +3768,11 @@ case "$host" in
SOURCES="$SOURCES $srcdir/src/core/linux/SDL_evdev_kbd.c"
SOURCES="$SOURCES $srcdir/src/core/freebsd/SDL_evdev_kbd_freebsd.c"
fi
# Set up files for wscons input
if test x$use_input_wscons = xyes; then
SOURCES="$SOURCES $srcdir/src/core/openbsd/SDL_wscons_kbd.c"
SOURCES="$SOURCES $srcdir/src/core/openbsd/SDL_wscons_mouse.c"
fi
# Set up other core UNIX files
SOURCES="$SOURCES $srcdir/src/core/linux/SDL_evdev_capabilities.c"
SOURCES="$SOURCES $srcdir/src/core/linux/SDL_threadprio.c"
+1
View File
@@ -297,6 +297,7 @@
#undef SDL_INPUT_LINUXEV
#undef SDL_INPUT_FBSDKBIO
#undef SDL_INPUT_LINUXKD
#undef SDL_INPUT_WSCONS
#undef SDL_JOYSTICK_HAIKU
#undef SDL_JOYSTICK_DINPUT
#undef SDL_JOYSTICK_XINPUT
+27
View File
@@ -0,0 +1,27 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
void SDL_WSCONS_Init();
void SDL_WSCONS_Quit();
void SDL_WSCONS_PumpEvents();
File diff suppressed because it is too large Load Diff
+130
View File
@@ -0,0 +1,130 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_events.h"
#include <sys/time.h>
#include <dev/wscons/wsconsio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <fcntl.h>
#include "../../events/SDL_mouse_c.h"
typedef struct SDL_WSCONS_mouse_input_data
{
int fd;
} SDL_WSCONS_mouse_input_data;
SDL_WSCONS_mouse_input_data* SDL_WSCONS_Init_Mouse()
{
SDL_WSCONS_mouse_input_data* mouseInputData = SDL_calloc(1, sizeof(SDL_WSCONS_mouse_input_data));
if (!mouseInputData) return NULL;
mouseInputData->fd = open("/dev/wsmouse",O_RDWR | O_NONBLOCK);
if (mouseInputData->fd == -1) {free(mouseInputData); return NULL; }
ioctl(mouseInputData->fd, WSMOUSEIO_SETMODE, WSMOUSE_COMPAT);
#ifdef WSMOUSEIO_SETVERSION
int version = WSMOUSEIO_EVENT_VERSION;
ioctl(inputData->fd, WSMOUSEIO_SETVERSION, &version);
#endif
return mouseInputData;
}
void updateMouse(SDL_WSCONS_mouse_input_data* inputData)
{
struct wscons_event events[64];
int type;
int n,i;
SDL_Mouse* mouse = SDL_GetMouse();
if ((n = read(inputData->fd, events, sizeof(events))) > 0)
{
n /= sizeof(struct wscons_event);
for (i = 0; i < n; i++)
{
type = events[i].type;
switch(type)
{
case WSCONS_EVENT_MOUSE_DOWN:
{
switch (events[i].value)
{
case 0: /* Left Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_BUTTON_LEFT);
break;
case 1: /* Middle Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_BUTTON_MIDDLE);
break;
case 2: /* Right Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_BUTTON_RIGHT);
break;
}
}
break;
case WSCONS_EVENT_MOUSE_UP:
{
switch (events[i].value)
{
case 0: /* Left Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_BUTTON_LEFT);
break;
case 1: /* Middle Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_BUTTON_MIDDLE);
break;
case 2: /* Right Mouse Button. */
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_BUTTON_RIGHT);
break;
}
}
break;
case WSCONS_EVENT_MOUSE_DELTA_X:
{
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, events[i].value * 2, 0);
break;
}
case WSCONS_EVENT_MOUSE_DELTA_Y:
{
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, 0, -events[i].value * 2);
break;
}
case WSCONS_EVENT_MOUSE_DELTA_W:
{
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL);
break;
}
case WSCONS_EVENT_MOUSE_DELTA_Z:
{
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, -events[i].value, SDL_MOUSEWHEEL_NORMAL);
break;
}
}
}
}
}
void SDL_WSCONS_Quit_Mouse(SDL_WSCONS_mouse_input_data* inputData)
{
if (!inputData) return;
close(inputData->fd);
free(inputData);
}
+4
View File
@@ -28,12 +28,16 @@
#ifdef SDL_INPUT_LINUXEV
#include "../../core/linux/SDL_evdev.h"
#elif defined SDL_INPUT_WSCONS
#include "../../core/openbsd/SDL_wscons.h"
#endif
void KMSDRM_PumpEvents(_THIS)
{
#ifdef SDL_INPUT_LINUXEV
SDL_EVDEV_Poll();
#elif defined SDL_INPUT_WSCONS
SDL_WSCONS_PumpEvents();
#endif
}
+6
View File
@@ -34,6 +34,8 @@
#ifdef SDL_INPUT_LINUXEV
#include "../../core/linux/SDL_evdev.h"
#elif defined SDL_INPUT_WSCONS
#include "../../core/openbsd/SDL_wscons.h"
#endif
/* KMS/DRM declarations */
@@ -839,6 +841,8 @@ KMSDRM_VideoInit(_THIS)
#ifdef SDL_INPUT_LINUXEV
SDL_EVDEV_Init();
#elif defined(SDL_INPUT_WSCONS)
SDL_WSCONS_Init();
#endif
/* Since we create and show the default cursor on KMSDRM_InitMouse() and
@@ -879,6 +883,8 @@ KMSDRM_VideoQuit(_THIS)
#ifdef SDL_INPUT_LINUXEV
SDL_EVDEV_Quit();
#elif defined(SDL_INPUT_WSCONS)
SDL_WSCONS_Quit();
#endif
/* Clear out the window list */