Sixty-five headers sat side by side in include/, so `#include "irq.h"` said nothing about where irq.h was or what it belonged to, and errno.h, stat.h and fcntl.h at the top shadowed the system's for any host tool built with -I./include. They are in folders now -- arch/ core/ fs/ dev/ gfx/ net/ uapi/ (and ldls/ for the Linux driver layer) -- and every include names the folder, as Linux's do: "core/proc.h". Done mechanically and checked the hard way: the kernel built from this tree disassembles identically to the one built from the tree before it. The full image boots, and userland is the same set of programs. Paths in docs and comments follow; docs/guides/layout.md has a table of what is where, and tools/fix-includes.py rewrites old-style includes from the folders in the tree, for code written before this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
99 lines
3.2 KiB
C
99 lines
3.2 KiB
C
#pragma once
|
|
|
|
#include "core/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.
|
|
// Absolute axes, for a pointing device that reports where it *is* rather than
|
|
// how far it moved -- a tablet, a touchscreen, or a VM's absolute pointer.
|
|
// Same numbering as Linux, because /dev/input/eventN claims to speak evdev.
|
|
#define ABS_X 0x00
|
|
#define ABS_Y 0x01
|
|
|
|
#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 SchOS 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
|