<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <HTML ><HEAD ><TITLE >Introduction</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Mouse Drivers" HREF="book1.html"><LINK REL="PREVIOUS" TITLE="Mouse Drivers" HREF="book1.html"><LINK REL="NEXT" TITLE="A simple mouse driver" HREF="c53.html"></HEAD ><BODY CLASS="CHAPTER" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Mouse Drivers</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="book1.html" ACCESSKEY="P" ><<< Previous</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="c53.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="CHAPTER" ><H1 ><A NAME="INTRO" ></A >Introduction</H1 ><DIV CLASS="NOTE" ><P ></P ><TABLE CLASS="NOTE" WIDTH="100%" BORDER="0" ><TR ><TD WIDTH="25" ALIGN="CENTER" VALIGN="TOP" ><IMG SRC="./stylesheet-images/note.gif" HSPACE="5" ALT="Note"></TD ><TH ALIGN="LEFT" VALIGN="CENTER" ><B >Earlier publication</B ></TH ></TR ><TR ><TD > </TD ><TD ALIGN="LEFT" VALIGN="TOP" ><P > Parts of this document first appeared in Linux Magazine under a ninety day exclusivity. </P ></TD ></TR ></TABLE ></DIV ><P > Mice are conceptually one of the simplest device interfaces in the Linux operating system. Not all mice are handled by the kernel. Instead there is a two layer abstraction. </P ><P > The kernel mouse drivers and userspace drivers for the serial mice are all managed by a system daemon called <TT CLASS="APPLICATION" >gpm</TT > - the general purpose mouse driver. <TT CLASS="APPLICATION" >gpm</TT > handles cutting and pasting on the text consoles. It provides a general library for mouse-aware applications and it handles the sharing of mouse services with the <TT CLASS="APPLICATION" >X Window System</TT > user interface. </P ><P > Sometimes a mouse speaks a sufficiently convoluted protocol that the protocol is handled by <TT CLASS="APPLICATION" >Gpm</TT > itself. Most of the mouse drivers follow a common interface called the bus mouse protocol. </P ><P > Each read from a bus mouse interface device returns a block of data. The first three bytes of each read are defined as follows: <DIV CLASS="TABLE" ><A NAME="AEN33" ></A ><P ><B >Table 1. Mouse Data Encoding</B ></P ><TABLE BORDER="1" BGCOLOR="#E0E0E0" CELLSPACING="0" CELLPADDING="4" CLASS="CALSTABLE" ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="TOP" >Byte 0</TD ><TD ALIGN="LEFT" VALIGN="TOP" >0x80 + the buttons currently down.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="TOP" >Byte 1</TD ><TD ALIGN="LEFT" VALIGN="TOP" >A signed value for the shift in X position</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="TOP" >Byte 2</TD ><TD ALIGN="LEFT" VALIGN="TOP" >A signed value for the shift in Y position</TD ></TR ></TBODY ></TABLE ></DIV > An application can choose to read more than 3 bytes. The rest of the bytes will be zero, or may optionally return some additional device-specific information. </P ><P > The position values are truncated if they exceed the 8bit range (that is -127 <= delta <= 127). While the value -128 does fit into a byte is not allowed. </P ><P > The <SPAN CLASS="MOUSEBUTTON" >buttons</SPAN > are numbered left to right as 0, 1, 2, 3.. and each button sets the relevant bit. So a user pressing the left and right button of a three button mouse will set bits 0 and 2. </P ><P > All mice are required to support the <TT CLASS="FUNCTION" >poll</TT > operation. Indeed pretty much every user of a mouse device uses <TT CLASS="FUNCTION" >poll</TT > to wait for mouse events to occur. </P ><P > Finally the mice support asynchronous I/O. This is a topic we have not yet covered but which I will explain after looking at a simple mouse driver. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="book1.html" ACCESSKEY="P" ><<< Previous</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="book1.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="c53.html" ACCESSKEY="N" >Next >>></A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Mouse Drivers</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" > </TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >A simple mouse driver</TD ></TR ></TABLE ></DIV ></BODY ></HTML >