An x86-64 operating system built from xv6, now largely rewritten: SMP, a copy-on-write root filesystem (SchFS), PCI/USB/virtio drivers, a TTF rasteriser, and a Linux-numbered syscall ABI. No history before this point -- the tree was never under version control. This commit exists so the rename that follows has something to undo to.
93 lines
2.9 KiB
C
93 lines
2.9 KiB
C
#pragma once
|
|
|
|
#include "types.h"
|
|
|
|
// Raw input events -- Linux's evdev interface.
|
|
//
|
|
// The console gives characters. That is the right thing for a shell and the
|
|
// wrong thing for everything else: a character stream has no key *releases*,
|
|
// no way to tell left shift from right, no notion of a key being held, and no
|
|
// mouse at all. A game holding W to walk forward, or a compositor deciding
|
|
// which window a click landed in, needs the events underneath the characters.
|
|
//
|
|
// The layout is Linux's, deliberately. It is what every program that reads input
|
|
// already speaks -- SDL, X, libinput, every game engine -- so a program that
|
|
// runs on Linux reads input here without a porting layer. It costs nothing to
|
|
// match: the struct is four fields.
|
|
//
|
|
// Nodes are /dev/input/event0 (keyboard) and /dev/input/event1 (mouse).
|
|
|
|
struct input_timeval {
|
|
int64 tv_sec;
|
|
int64 tv_usec;
|
|
};
|
|
|
|
struct input_event {
|
|
struct input_timeval time;
|
|
uint16 type;
|
|
uint16 code;
|
|
int32 value;
|
|
};
|
|
|
|
// Event types.
|
|
#define EV_SYN 0x00
|
|
#define EV_KEY 0x01
|
|
#define EV_REL 0x02
|
|
#define EV_ABS 0x03
|
|
#define EV_MSC 0x04
|
|
|
|
#define SYN_REPORT 0
|
|
|
|
// Relative axes.
|
|
#define REL_X 0x00
|
|
#define REL_Y 0x01
|
|
#define REL_WHEEL 0x08
|
|
|
|
// Buttons live in the EV_KEY code space alongside keys, which is why the
|
|
// keyboard's codes stop well below 0x100.
|
|
#define BTN_LEFT 0x110
|
|
#define BTN_RIGHT 0x111
|
|
#define BTN_MIDDLE 0x112
|
|
|
|
// Key codes worth naming. The rest are the AT scancode-set-1 numbers, which
|
|
// Linux's keycodes were derived from and still match for everything below
|
|
// 0x54 -- that is not a coincidence and it is why the PS/2 path needs no
|
|
// translation table for unprefixed bytes.
|
|
#define KEY_RESERVED 0
|
|
#define KEY_ESC 1
|
|
#define KEY_ENTER 28
|
|
#define KEY_LEFTCTRL 29
|
|
#define KEY_LEFTSHIFT 42
|
|
#define KEY_RIGHTSHIFT 54
|
|
#define KEY_LEFTALT 56
|
|
#define KEY_SPACE 57
|
|
#define KEY_RIGHTCTRL 97
|
|
#define KEY_RIGHTALT 100
|
|
#define KEY_HOME 102
|
|
#define KEY_UP 103
|
|
#define KEY_PAGEUP 104
|
|
#define KEY_LEFT 105
|
|
#define KEY_RIGHT 106
|
|
#define KEY_END 107
|
|
#define KEY_DOWN 108
|
|
#define KEY_PAGEDOWN 109
|
|
#define KEY_INSERT 110
|
|
#define KEY_DELETE 111
|
|
#define KEY_LEFTMETA 125
|
|
#define KEY_RIGHTMETA 126
|
|
|
|
#define KEY_MAX 255
|
|
|
|
// EVIOCGRAB -- take/release exclusive access to a device.
|
|
//
|
|
// Linux's _IOW('E', 0x90, int). Spelled as the resulting constant rather than
|
|
// built from an _IOW macro because Schunix has no ioctl-encoding macros and
|
|
// inventing a set just for this would be a bigger change than the feature.
|
|
// A non-zero argument grabs, zero releases; the argument is passed by value.
|
|
#define EVIOCGRAB 0x40044590
|
|
|
|
// Which device an event came from. Both are minor numbers under the input
|
|
// major, and both are the index into the driver's array.
|
|
#define INPUT_KBD 0
|
|
#define INPUT_MOUSE 1
|
|
#define NINPUTDEV 2
|