149 lines
21 KiB
HTML
149 lines
21 KiB
HTML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Be Book - System Overview - The Input Server</title><link rel="stylesheet" href="be_book.css" type="text/css" media="all" /><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./images/favicon.ico" /><!--[if IE]>
|
||
<link rel="stylesheet" type="text/css" href="be_book_ie.css" />
|
||
<![endif]--><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="Access, BeOS, BeBook, API" /><link rel="start" href="index.html" title="The Be Book" /><link rel="up" href="TheInputServer_Overview.html" title="The Input Server" /><link rel="prev" href="BInputDevice_Overview.html" title="BInputDevice" /><link rel="next" href="BInputServerFilter_Overview.html" title="BInputServerFilter" /></head><body><div id="header"><div id="headerT"><div id="headerTL"><a accesskey="p" href="BInputDevice_Overview.html" title="BInputDevice"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a accesskey="u" href="TheInputServer_Overview.html" title="The Input Server"><img src="./images/navigation/up.png" alt="Up" /></a> <a accesskey="n" href="BInputServerFilter_Overview.html" title="BInputServerFilter"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="headerTR"><div id="navigpeople"><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div><div class="navigboxed" id="navigindex"><a accesskey="i" href="ClassIndex.html" title="Index">I</a></div><div class="navigboxed" id="naviglang" title="English">en</div></div><div id="headerTC">The Be Book - System Overview - The Input Server</div></div><div id="headerB">Prev: <a href="BInputDevice_Overview.html">BInputDevice</a> Up: <a href="TheInputServer_Overview.html">The Input Server</a> Next: <a href="BInputServerFilter_Overview.html">BInputServerFilter</a></div><hr /></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h2 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BInputServerDevice_Overview"></a>BInputServerDevice</h2></div></div></div><p><code class="classname">BInputServerDevice</code> is a base class for input devices; these are instances
|
||
of <code class="classname">BInputServerDevice</code> subclasses that generate input events. In most
|
||
cases, an input device corresponds to a device driver that handles a
|
||
specific brand or model of hardware (mouse, keyboard, tablet, etc.), but
|
||
it doesn't have to: an input device can get events from the Net, or
|
||
generate them algorithmically, for example. Also, a single
|
||
<code class="classname">BInputServerDevice</code> can handle more than one device driver.</p><p><code class="classname">BInputServerDevice</code> objects are created and deleted by the Input Server
|
||
only—you never create or delete these objects themselves.</p><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BInputServerDevice_Overview_Starting_Sending_Messages"></a>Starting and Sending Messages</h3></div></div></div><p>For each device that your object registers, it gets a
|
||
<a class="link" href="BInputServerDevice.html#BInputServerDevice_Start" title="Start(), Stop()"><code class="methodname">Start()</code></a> function
|
||
call. This is the Input Server's way of telling your object that it can
|
||
begin generating input events (for the designated device). So far, all of
|
||
this—from the add-on load to the
|
||
<a class="link" href="BInputServerDevice.html#BInputServerDevice_Start" title="Start(), Stop()"><code class="methodname">Start()</code></a> call—happens within
|
||
a single Input Server thread (for all input devices). When your
|
||
<a class="link" href="BInputServerDevice.html#BInputServerDevice_Start" title="Start(), Stop()"><code class="methodname">Start()</code></a>
|
||
function is called, you should spawn a thread so your object can generate
|
||
events without blocking the Server. Events are generated and sent through
|
||
the <a class="link" href="BInputServerDevice.html#BInputServerDevice_EnqueueMessage" title="EnqueueMessage()"><code class="methodname">EnqueueMessage()</code></a>
|
||
function.</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="id532698"></a>Device Types and Control Messages</h3></div></div></div><p>The Input Server knows about two types of devices: keyboards, and
|
||
pointing devices (mice, tablets, etc). When you register your object's
|
||
devices (through
|
||
<a class="link" href="BInputServerDevice.html#BInputServerDevice_RegisterDevices" title="RegisterDevices(), UnregisterDevices()"><code class="methodname">RegisterDevices()</code></a>)
|
||
you have to indicate the device type.
|
||
The Input Server uses the device type to predicate the input device
|
||
control messages it sends to the devices. These messages, delivered in
|
||
<a class="link" href="BInputServerDevice.html#BInputServerDevice_Control" title="Control()"><code class="methodname">Control()</code></a>
|
||
calls, tell a device that there's been a change downstream that
|
||
applies specifically to that type of device. For example, when the user
|
||
changes the mouse speed, each pointing device receives a
|
||
<code class="constant">B_MOUSE_SPEED_CHANGED</code> notification.</p><p>The Be-defined control messages are predicated on device type only.</p><p>If your
|
||
<a class="link" href="BInputServerDevice.html" title="BInputServerDevice"><code class="classname">BInputServerDevice</code></a>
|
||
object manages a device other than a pointer
|
||
or a keyboard, you tell the Input Server that the device is undefined. In
|
||
this case, the Input Server won't send your device any device-specific
|
||
messages; to send your device a message you (or an application that knows
|
||
about your device) have to use a
|
||
<a class="link" href="BInputServerDevice.html" title="BInputServerDevice"><code class="classname">BInputServerDevice</code></a>
|
||
object.</p><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="id532765"></a>Pointing Devices</h4></div></div></div><p>Pointing devices such as mice, trackballs, drawing tablets, etc. generate
|
||
<code class="constant">B_MOUSE_MOVED</code> messages (which trigger a BView's MouseMoved() function)
|
||
featuring a where field representing the cursor's location in view
|
||
co-ordinates. Unfortunately, your
|
||
<a class="link" href="BInputServerDevice.html" title="BInputServerDevice"><code class="classname">BInputServerDevice</code></a> doesn't know
|
||
anything about views; that's the App Server's job. You'll still need to
|
||
add this information to the <code class="constant">B_MOUSE_MOVED</code> messages generated by your
|
||
<a class="link" href="BInputServerDevice.html" title="BInputServerDevice"><code class="classname">BInputServerDevice</code></a>,
|
||
and the App Server will adjust it to view
|
||
co-ordinates for you.</p><p>When generating a <code class="constant">B_MOUSE_MOVED</code> message, you add x and y fields in one of
|
||
two ways:</p><ul class="itemizedlist"><li><p>an offset relative to the cursor's previous position (<code class="constant">B_INT32_TYPE</code>
|
||
values)</p></li><li><p>an absolute position expressed in the range 0.0 to 1.0 (<code class="constant">B_FLOAT_TYPE</code>
|
||
values)</p></li></ul><p>Mice always use relative locations; tablets can use either (though they
|
||
usually provide absolute values).</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="id532847"></a>Relative Locations</h4></div></div></div><p>All mice (and some drawing tablets) express the pointer location relative
|
||
to its previous position. If your pointing device is operating in
|
||
relative co-ordinate mode, you add x and y entries as <code class="constant">B_INT32_TYPE</code> values
|
||
in device-defined units. The App Server interprets these units as pixels,
|
||
so you may need to scale your output:</p><pre class="programlisting example cpp"><span class="type">int32</span> <code class="varname">xVal</code>, <code class="varname">yVal</code>;
|
||
...
|
||
<code class="varname">event</code>-><code class="methodname">AddInt32</code>( "x", <code class="varname">xVal</code> );
|
||
<code class="varname">event</code>-><code class="methodname">AddInt32</code>( "y", <code class="varname">yVal</code> );</pre></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="id532907"></a>Absolute Locations</h4></div></div></div><p>Drawing tablets or other pointing devices that provide absolute locations
|
||
add the x and y entries as <code class="constant">B_FLOAT_TYPEs</code>:</p><pre class="programlisting example cpp"><span class="type">float</span> <code class="varname">xVal</code>, <code class="varname">yVal</code>;
|
||
...
|
||
<code class="varname">event</code>-><code class="methodname">AddFloat</code>( "x", <code class="varname">xVal</code> );
|
||
<code class="varname">event</code>-><code class="methodname">AddFloat</code>( "y", <code class="varname">yVal</code> );</pre><p>These values must be in the range [0.0 to 1.0]. The app_server scales
|
||
them to the screen's co-ordinate system so (0.0, 0.0) is the left-top,
|
||
and (1.0, 1.0) is the right-bottom of the screen. This lets the pointing
|
||
device work with any screen resolution, automatically.</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="id532972"></a>Now where?</h4></div></div></div><p>When the Application Server receives one of these <code class="constant">B_MOUSE_MOVED</code> messages,
|
||
it converts the x and y values into absolute values in the target view's
|
||
co-ordinate system, and then throws away the x and y entries in the
|
||
message. Because of this, and the fact that some applications might want
|
||
more accurate positional information from tablets, fill in the
|
||
<code class="varname">be:tablet_x</code> and <code class="varname">be:tablet_y</code> fields as well:</p><pre class="programlisting example cpp"><span class="type">float</span> <code class="varname">xVal</code>, <code class="varname">yVal</code>;
|
||
...
|
||
<code class="varname">event</code>-><code class="methodname">AddFloat</code>( "x", <code class="varname">xVal</code> );
|
||
<code class="varname">event</code>-><code class="methodname">AddFloat</code>( "y", <code class="varname">yVal</code> );
|
||
<code class="varname">event</code>-><code class="methodname">AddFloat</code>( "be:tablet_x", <code class="varname">xVal</code> );
|
||
<code class="varname">event</code>-><code class="methodname">AddFloat</code>( "be:tablet_y", <code class="varname">yVal</code> );</pre></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="id533068"></a>Other Useful Information</h4></div></div></div><p>Pressure information is stored in the
|
||
<code class="varname">be:tablet_pressure</code> field, as a
|
||
float in the range [0.0 to 1.0] (minimum pressure to maximum pressure):</p><pre class="programlisting example cpp"><span class="type">float</span> <code class="varname">pressure</code>;
|
||
...
|
||
<code class="varname">event</code>-><code class="methodname">AddFloat</code>( "be:tablet_pressure", <code class="varname">pressure</code> );</pre><p>If the tablet supports tilt information, store it in <code class="varname">be:tablet_tilt_x</code> and
|
||
<code class="varname">be:tablet_tilt_y</code>, scaling the information to the range [0.0 to 1.0]. A
|
||
tilt of (-1.0, -1.0) tilts to the left-top, (1.0, 1.0) tilts to the
|
||
right-bottom, and (0.0, 0.0) is no tilt.</p><pre class="programlisting example cpp"><span class="type">float</span> <code class="varname">tilt_x</code>, <code class="varname">tilt_y</code>;
|
||
...
|
||
<code class="varname">event</code>-><code class="methodname">AddFloat</code>( "be:tablet_tilt_x", <code class="varname">tilt_x</code> );
|
||
<code class="varname">event</code>-><code class="methodname">AddFloat</code>( "be:tablet_tilt_y", <code class="varname">tilt_y</code> );</pre><p>Tablets with pens that support an eraser store the eraser's state in the
|
||
<code class="varname">be:tablet_eraser</code> field. A value of 1 means the pen is reversed (i.e. the
|
||
eraser is on), and 0 means it should behave normally.</p><pre class="programlisting example cpp"><span class="type">int32</span> <code class="varname">erase_mode</code>;
|
||
...
|
||
<code class="varname">event</code>-><code class="methodname">AddInt32</code>( "be:tablet_eraser", <code class="varname">erase_mode</code> );</pre></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="id533213"></a>Device State</h3></div></div></div><p>The <a class="link" href="BInputServerDevice.html#BInputServerDevice_Control" title="Control()"><code class="methodname">Control()</code></a>
|
||
protocol is designed to accommodate queries (in addition to
|
||
commands). Currently, however, the Input Server maintains the keyboard
|
||
and pointing device state and answers these queries itself; it doesn't
|
||
forward any of the Be-defined query messages. For example, when an
|
||
application asks for the current mouse speed setting (through
|
||
<a class="link" href="TheInputServer_Functions.html#get_mouse_speed"><code class="function">get_mouse_speed()</code></a>),
|
||
the query gets no further than the Input Server
|
||
itself—it doesn't get passed as a control message to a pointing
|
||
device.</p><p>If you're designing a
|
||
<a class="link" href="BInputServerDevice.html" title="BInputServerDevice"><code class="classname">BInputServerDevice</code></a>
|
||
that manages a keyboard or
|
||
pointing device, you must keep in mind that your device is not
|
||
responsible for its "Be-defined" state. The elements of the
|
||
state—mouse speed, key map, etc.—correspond to the control
|
||
messages listed in "Input Device Control Messages".</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="id533261"></a>Dynamic Devices</h3></div></div></div><p>As hardware devices are attached and detached from the computer, you can
|
||
add and remove items from your
|
||
<a class="link" href="BInputServerDevice.html" title="BInputServerDevice"><code class="classname">BInputServerDevice</code></a>'s
|
||
list of registered devices (by calling
|
||
<a class="link" href="BInputServerDevice.html#BInputServerDevice_RegisterDevices" title="RegisterDevices(), UnregisterDevices()"><code class="methodname">RegisterDevice()</code></a>
|
||
/ <a class="link" href="BInputServerDevice.html#BInputServerDevice_UnregisterDevices"><code class="methodname">UnregisterDevice()</code></a>). But your object
|
||
has to first notice that a physical device has been added or removed. It
|
||
does this by placing a node monitor on the device directory
|
||
(<code class="filename">/dev</code>). As a
|
||
convenience—and to help conserve resources—the
|
||
<a class="link" href="BInputServerDevice.html" title="BInputServerDevice"><code class="classname">BInputServerDevice</code></a>
|
||
class provides the
|
||
<a class="link" href="BInputServerDevice.html#BInputServerDevice_StartMonitoringDevice" title="StartMonitoringDevice(), StopMonitoringDevice()"><code class="methodname">Start/StopMonitoringDevices()</code></a>
|
||
functions which install and remove node monitors for you.</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="id533323"></a>Creating and Registering</h3></div></div></div><p>To create a new input device, you must:</p><ul class="itemizedlist"><li><p>create a subclass of
|
||
<a class="link" href="BInputServerDevice.html" title="BInputServerDevice"><code class="classname">BInputServerDevice</code></a></p></li><li><p>implement the
|
||
<a class="link" href="TheInputServer_Functions.html#instantiate_input_device" title="instantiate_input_device()"><code class="function">instantiate_input_device()</code></a>
|
||
C function to create an instance of your
|
||
<a class="link" href="BInputServerDevice.html" title="BInputServerDevice"><code class="classname">BInputServerDevice</code></a> subclass</p></li><li><p>compile the class and the function as an add-on</p></li><li><p>install the add-on in one of the input device directories</p></li></ul><p>At boot time, the Input Server loads the add-ons it finds in the input
|
||
device directories. For each add-on it loads, the Server invokes
|
||
<a class="link" href="TheInputServer_Functions.html#instantiate_input_device" title="instantiate_input_device()"><code class="function">instantiate_input_device()</code></a>
|
||
to get a pointer to the add-on's
|
||
<a class="link" href="BInputServerDevice.html" title="BInputServerDevice"><code class="classname">BInputServerDevice</code></a>
|
||
object. After constructing the object, the Server
|
||
calls
|
||
<a class="link" href="BInputServerDevice.html#BInputServerDevice_InitCheck" title="InitCheck()"><code class="methodname">InitCheck()</code></a>
|
||
to give the add-on a chance to bail out if the
|
||
constructor failed. If the add-on wants to continue, it calls
|
||
<a class="link" href="BInputServerDevice.html#BInputServerDevice_RegisterDevices" title="RegisterDevices(), UnregisterDevices()"><code class="methodname">RegisterDevices()</code></a>
|
||
(from within
|
||
<a class="link" href="BInputServerDevice.html#BInputServerDevice_InitCheck" title="InitCheck()"><code class="methodname">InitCheck()</code></a>)
|
||
to tell the Server which
|
||
physical or virtual devices it handles.</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BInputServerDevice_Overview_Installing_An_Input_Device"></a>Installing an Input Device</h3></div></div></div><p>The input server looks for input devices in the
|
||
<code class="filename">input_server/devices</code>
|
||
subdirectories of <code class="constant">B_BEOS_ADDONS_DIRECTORY</code>,
|
||
<code class="constant">B_COMMON_ADDONS_DIRECTORY</code>, and
|
||
<code class="constant">B_USER_ADDONS_DIRECTORY</code>.</p><ul class="itemizedlist"><li><p>You can install your input devices in the latter two
|
||
directories—i.e. those under <code class="constant">B_COMMON_ADDONS_DIRECTORY</code>, and
|
||
<code class="constant">B_USER_ADDONS_DIRECTORY</code>.</p></li><li><p>The <code class="constant">B_BEOS_ADDONS_DIRECTORY</code> is reserved for add-ons that are supplied
|
||
by the BeOS.</p></li></ul></div></div><div id="footer"><hr /><div id="footerT">Prev: <a href="BInputDevice_Overview.html">BInputDevice</a> Up: <a href="TheInputServer_Overview.html">The Input Server</a> Next: <a href="BInputServerFilter_Overview.html">BInputServerFilter</a> </div><div id="footerB"><div id="footerBL"><a href="BInputDevice_Overview.html" title="BInputDevice"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a href="TheInputServer_Overview.html" title="The Input Server"><img src="./images/navigation/up.png" alt="Up" /></a> <a href="BInputServerFilter_Overview.html" title="BInputServerFilter"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="footerBR"><div><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div></div><div id="footerBC"><a href="http://www.access-company.com/home.html" title="ACCESS Co."><img alt="Access Company" src="./images/access_logo.png" /></a></div></div></div><div id="licenseFooter"><div id="licenseFooterBL"><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" title="Creative Commons License"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by-nc-nd/3.0/88x31.png" /></a></div><div id="licenseFooterBR"><a href="./LegalNotice.html">Legal Notice</a></div><div id="licenseFooterBC"><span id="licenseText">This work is licensed under a
|
||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative
|
||
Commons Attribution-Non commercial-No Derivative Works 3.0 License</a>.</span></div></div></body></html>
|