wscons: Move to its own device type

This reduces ifdefs and avoids overloading evdev as something it is not.
This commit is contained in:
Kenny Levinsen 2022-03-29 10:41:16 +02:00
parent 684dd61945
commit 0462e9331d
7 changed files with 51 additions and 27 deletions

View file

@ -9,11 +9,6 @@
#include <sys/sysmacros.h>
#elif defined(__FreeBSD__)
#include <dev/evdev/input.h>
#elif defined(__NetBSD__)
#include <stdlib.h>
#include <sys/stat.h>
#else
#error Unsupported platform
#endif
#include "evdev.h"
@ -30,28 +25,15 @@ int path_is_evdev(const char *path) {
int evdev_revoke(int fd) {
return ioctl(fd, EVIOCREVOKE, NULL);
}
#endif
#if defined(__linux__)
int dev_is_evdev(dev_t device) {
return major(device) == INPUT_MAJOR;
}
#elif defined(__NetBSD__)
int dev_is_evdev(dev_t device) {
return major(device) == getdevmajor("wskbd", S_IFCHR) ||
major(device) == getdevmajor("wsmouse", S_IFCHR) ||
major(device) == getdevmajor("wsmux", S_IFCHR);
}
int path_is_evdev(const char *path) {
const char *wskbd = "/dev/wskbd";
const char *wsmouse = "/dev/wsmouse";
const char *wsmux = "/dev/wsmux";
return strncmp(path, wskbd, STRLEN(wskbd)) == 0 ||
strncmp(path, wsmouse, STRLEN(wsmouse)) == 0 ||
strncmp(path, wsmux, STRLEN(wsmouse)) == 0;
(void)path;
return 0;
}
int evdev_revoke(int fd) {
(void)fd;
return 0;
}
#else
#error Unsupported platform
#endif

27
common/wscons.c Normal file
View file

@ -0,0 +1,27 @@
#include <stdlib.h>
#include <string.h>
#if defined(__NetBSD__)
#include <stdlib.h>
#include <sys/stat.h>
#endif
#include "wscons.h"
#define STRLEN(s) ((sizeof(s) / sizeof(s[0])) - 1)
#if defined(__NetBSD__)
int path_is_wscons(const char *path) {
const char *wskbd = "/dev/wskbd";
const char *wsmouse = "/dev/wsmouse";
const char *wsmux = "/dev/wsmux";
return strncmp(path, wskbd, STRLEN(wskbd)) == 0 ||
strncmp(path, wsmouse, STRLEN(wsmouse)) == 0 ||
strncmp(path, wsmux, STRLEN(wsmouse)) == 0;
}
#else
int path_is_wscons(const char *path) {
(void)path;
return 0;
}
#endif

View file

@ -4,9 +4,4 @@
int evdev_revoke(int fd);
int path_is_evdev(const char *path);
#if defined(__linux__) || defined(__NetBSD__)
#include <sys/types.h>
int dev_is_evdev(dev_t device);
#endif
#endif

View file

@ -13,6 +13,7 @@ enum seat_device_type {
SEAT_DEVICE_TYPE_NORMAL,
SEAT_DEVICE_TYPE_EVDEV,
SEAT_DEVICE_TYPE_DRM,
SEAT_DEVICE_TYPE_WSCONS,
};
struct seat_device {

6
include/wscons.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef _SEATD_WSCONS_H
#define _SEATD_WSCONS_H
int path_is_wscons(const char *path);
#endif

View file

@ -114,6 +114,7 @@ server_files = [
'common/connection.c',
'common/evdev.c',
'common/drm.c',
'common/wscons.c',
'seatd/poller.c',
'seatd/seat.c',
'seatd/client.c',

View file

@ -17,6 +17,7 @@
#include "protocol.h"
#include "seat.h"
#include "terminal.h"
#include "wscons.h"
static int seat_close_client(struct client *client);
static int vt_close(int vt);
@ -235,6 +236,8 @@ struct seat_device *seat_open_device(struct client *client, const char *path) {
type = SEAT_DEVICE_TYPE_EVDEV;
} else if (path_is_drm(sanitized_path)) {
type = SEAT_DEVICE_TYPE_DRM;
} else if (path_is_wscons(sanitized_path)) {
type = SEAT_DEVICE_TYPE_WSCONS;
} else {
log_errorf("%s is not a supported device type ", sanitized_path);
errno = ENOENT;
@ -281,6 +284,9 @@ struct seat_device *seat_open_device(struct client *client, const char *path) {
case SEAT_DEVICE_TYPE_EVDEV:
// Nothing to do here
break;
case SEAT_DEVICE_TYPE_WSCONS:
// Nothing to do here
break;
default:
log_error("Invalid seat device type");
abort();
@ -333,6 +339,9 @@ static int seat_deactivate_device(struct seat_device *seat_device) {
return -1;
}
break;
case SEAT_DEVICE_TYPE_WSCONS:
// Nothing to do here
break;
default:
log_error("Invalid seat device type");
abort();
@ -382,6 +391,9 @@ static int seat_activate_device(struct client *client, struct seat_device *seat_
case SEAT_DEVICE_TYPE_EVDEV:
errno = EINVAL;
return -1;
case SEAT_DEVICE_TYPE_WSCONS:
// Nothing to do here
break;
default:
log_error("Invalid seat device type");
abort();