|
An Introduction to the Input Server
One of the many upcoming changes in the BeOS is in the world of input devices and events. The Input Server, slated to debut in R4, is a server that deals with all things "input." Specifically, it serves three functions: manages input devices such as keyboards and mice; hosts a stream of events that those devices generate; and dispatches those events that make it through the stream.
Managing Input Devices
The Input Server is a pretty dumb piece of software. (Cue to
Alex: roll your eyes and say, "What do you expect Hiroshi,
you wrote it.") On its own, the server doesn't know how a
keyboard or a mouse works; it relies on BInputServerDevice
add-ons to tell it.
BInputServerDevice
is a base class from which all input
device add-ons must derive. It provides the basic framework
of virtual hook functions and non-virtual member functions
that the Input Server uses to communicate with an add-on,
and that the add-on can use to talk back to the server. To
give a sneak peak of the API, some of the virtuals include
InitCheck()
, Start()
, Stop()
, and Control()
. The common
sequence of the life of an input device is this:
BInputServerDevice
-derived object.
InitCheck()
on the object. The
object determines whether it is capable of doing its job
-- that is, generating input events.
/dev
. If the object is happy, it registers with
the Input Server any input device(s) it finds, and
returns B_NO_ERROR
. An error return causes the Input
Server to promptly destruct the object and unload the
add-on.
Start()
. The
system automatically starts keyboards and mice at boot
time. Any other type of device (an "undefined" input
device that the system doesn't have any special knowledge
about) can be started by an application using new API in
the Interface Kit.
Control()
-ed at any time. Think of Control()
as the ioctl()
equivalent in input device parlance.
Examples of system-defined control messages include
keymap changes and mouse speed changes.
Generating Input Events
Once a BInputServerDevice
-derived object's input device is
up and running, its primary task is to generate input
events. These events are expressed as BMessages. For
example, a keyboard input device will most likely generate
B_KEY_DOWN
and B_KEY_UP
messages. Similarly, a mouse input
device will probably generate B_MOUSE_UP
, B_MOUSE_DOWN
, and
B_MOUSE_MOVED
events.
There is nothing that prevents an input device from putting
arbitrary data in any of the BMessages
it generates. So, for
example, a tablet may generate the aforementioned mouse
events with extra data such as pressure and proximity. Any
information packed into the BMessages
is delivered
unmolested by the input server.
When an event is ready to be shipped off, an input device
enqueues it into the Input Server's event stream. Some
BHandler
(most likely a BView
) down the line eventually
receives the event by way of the usual hook functions such
as KeyDown()
, MouseDown()
, and MouseMoved()
.
The Input Event Stream
The Input Server's event stream is open for inspection and
alteration by anyone in the system. This is achieved through
another set of add-ons called BInputServerFilter
. Like
BInputServerDevice
, BInputServerFilter
is a base class for input filter add-ons to the Input Server.
An input filter add-on is privy to all the events that pass
through the Input Server's event stream. A filter may
inspect, alter, generate, or completely drop input events.
It's similar in some ways to the Interface Kit's
BMessageFilter
, but much more low-level. A
BInputServerFilter
sees all events that exist in the system;
BMessageFilters
are associated with a specific BLooper
and
thus see only the events targeted to its BLooper
. Also,
filters in the Input Server can generate additional events
in place of, or in addition to, the original input event
that it was invoked with.
Conclusion
With the introduction of loadable input device objects, the Input Server enables the BeOS to be used with a wide variety of input devices (and more than one of them at once too). And with the advent of input filters, the Input Server opens the door to a new class of tricks, hacks, and (gulp) pranks for the creative developer. It's going to be fun.