1 / 10

On using the mouse

On using the mouse. A brief introduction to LIBGPM: the General Purpose Mouse programming interface. The Linux “gpm” package. It’s a mouse server for the Linux console It “hides” details about mouse hardware Intended for use with text-based programs But we can use it with graphics programs

Download Presentation

On using the mouse

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. On using the mouse A brief introduction to LIBGPM: the General Purpose Mouse programming interface

  2. The Linux “gpm” package • It’s a mouse server for the Linux console • It “hides” details about mouse hardware • Intended for use with text-based programs • But we can use it with graphics programs • Requires that the gpm daemon is running • Type ‘info gpm’ to see official information • Also an online article by Pradeep Padala

  3. Programming steps • Your client application must establish a connection with the gpm server-daemon • You need a header-file: #include <gpm.h> • You declare an important data-structure: Gpm_Connect conn; • You will need to initialize its four fields • Then you call Gpm_Open( &conn, 0 ); • Returns -1 if unsuccessful (otherwise 0)

  4. Fields to be initialized conn.eventMask = ~0; // events of interest conn.defaultMask = 0; // to handle for you conn.minMod = 0; // lowest modifier conn.maxMod = ~0; // highest modifer

  5. Responding to mouse activity • You create your own ‘handler’ function for those mouse events that you wish to act upon • Prototype of the handler-function is: int my_handler( Gpm_Event *evt, void *my_data ); • To install the handler, use this assignment: gpm_handler = my_handler; • Whenever the mouse is moved, or its buttons are pressed or released, your function executes

  6. Useful fields in Gpm_Event Gpm_Event *evt; evt->type == 1: // indicates a mouse-move evt->x, evt->y: // current mouse ‘hot-spot’ evt->dx, evt->dy: // changes in position(+/-) NOTE: Remember that GPM was developed for text-based applications, so the hot-spot coordinates are character-cell locations (not graphics-pixel locations)

  7. A typical program loop This loop allows normal keyboard input to continue being processed (e.g., echoed, buffered) while any mouse activities are processed by your handler (or else by a default handler supplied by the daemon) int c; While ( ( c = Gpm_Getc( stdin ) ) != EOF ); Gpm_Close();

  8. A simple text-mode demo • Pradeep Padala has published a short C program that illustrates ‘barebones’ usage of the gpm package (from Linux Journal) • We have adapted his code for C++ • Our demo is called ‘trymouse.cpp’ • It’s compiled like this: $ g++ trymouse.cpp –lgpm –o trymouse

  9. A simple graphics demo • We have created a minimal graphics demo • It shows how you could use the mouse to move a ‘slider’ object (e.g.,in Pong game) • It’s called ‘gpmslide.cpp’ • You compile it like this: $ g++ gpmslide.cpp –lgpm –o gpmslide

  10. In-class exercises • Compile and run the ‘trymouse.cpp’ demo • Compile and run the ‘gpmslide.cpp’ demo • Look at the C++ source-code in the demos • Can you replace the keyboard-based user controls (in your earlier pong animation) with mouse-based user-controls? • Can you incorporate mouse-based control into your 3D wire-frame model animation?

More Related