Adding Multiple Mice Support to FLTK using MPX

Posted by Benjamin Close on November 25, 2008 under OpenSource, UniSA | 6 Comments to Read

For a while now I’ve been working on modifying FLTK to support multiple Mice. We need this functionality for applications we are working on. FLTK was chosen for a number of reasons. 

  1. It’s light weight
  2. It’s cross platform
  3. It was already in use by the applications being extended.
However, FLTK didn’t support multiple mice out the box. Multiple Mice support exists both under Win32 via the RAWINPUT api and under Xorg via MPX.
Though support in the various toolkits is still lacking. Not surprizing considering how recent MPX/RAWINPUT is.

MPX was the natural choice for the first implementation of multiple choice in a toolkit. 
MPX is built into the windowing system hence focus, grabs and cursor rending is all semi transparently delt with where as RAWINPUT has you doing most the work yourself.
Hence I set about modifying FLTK to support Multiple Mice using MPX.
Results so far have been quite good. Due to FLTK internally doing most of it’s own component hit testing, having to deal with a window per component wasn’t needed. Instead a simple API extending the existing toolkit has been created.
The patch implementing this API and the relevant glue to use it is available at: http://wcl.ml.unisa.edu.au/~closebs/downloads/fltk-1.3-mpx.patch
This patch against the current 1.3 SVN (rev 6524) development branch and provides the following API extensions:
Creation of FL/Fl_Mouse.H which defines two important types:
Types:
  • FL_MouseID – A type indicating the id of a mouse
  • FL_Mouse   – A type that records information about a mouse (ie x, y, button state, etc)
Functions/Variables
New functions/variarables in FL/Fl.H
  • FL::e_mouse_id       – The id of the last mouse to cause an event
  • FL::e_last_mouseid – The id of the last mouse in the system
  • Fl::grab(Fl_MouseID)- Put a grab on a specific mouse
  • Fl::get_last_mouseid- Return the ID of the last mouse know to the toolkit
  • Fl::create_mouse() – Register a new mouse with the toolkit
  • Fl::event_mouse_id()- Return the id of the mouse that caused the last event
There has also been a number of changes to existing functions but all in a way which should be API compatible – sadly not ABI compatible.
These changes basically support passing in mouse id’s or storage of grabs/focus per mouse, etc.
There’s also been a test application created: test/multiplemice
This application, whilst very simple shows an example use of the MULTIPLE_MICE functionality. In it you can use two mice to drag two FLTK widgets around at the same time. 

I want to try

If you want to give the FLTK changes a shot it’s fairly simple all you have to do is:

 

  • Build a version of Xorg with MPX support (see http://wearables.unisa.edu.au/mpx) for details.
  • Build a version of xinput with MPX support
    • This will allow you to create multiple mice via
      xinput create-master mymouse
      xinput list –short       # Take note of one of the mouse id’s, lets call it x and mymouse id y 
      xinput reattach  x y
  • Grab the latest version of the 1.3 branch of FLTK from SVN (http://fltk.org/svn.php)
  • Apply the patch at http://wcl.ml.unisa.edu.au/~closebs/downloads/fltk-1.3-mpx.patch
    • patch -p0 < fltk-1.3-mpx.patch
  • Configure with multiple mice support: ./configure –enable-multiplemice
  • Build the toolkit: make
  • Test the multiple mice application: test/multiplemice

 

Future

Win32 support is currently under way with large chunks being already done. Though the lack of native cursor rendering under Win32 is causing greif. Other patches not far around the corner are a custom cursor patch, which allows a custom cursor per mouse as well as the ability to capture input events from the toolkit and inject input events into the toolkit – great for distributed event reconstruction.



Donations keep this site alive

  • Shon said,

    I am simple dying for your work to be successful. Please keep up the good work!

    (in reference to multi-mice support in fltk)

  • vince said,

    Hey,
    this article is great, but where can I find how old it is ?
    It may be way simpler to do that today, I hope so :p

  • Benjamin Close said,

    The article was posted: Posted by Benjamin Close on November 25, 2008. A few things have changed since then but this is still the current way to use XInput2

  • vince said,

    I swear I looked for a date !
    thx for your answer
    greetings

  • vince said,

    Btw, I understood that we don’t need to “Build a version of Xorg with MPX support” anymore, since it is supported since Xorg 1.7 since ± october 2009 :
    http://who-t.blogspot.com/2009/10/xi2-and-mpx-released.html

    For the rest, I’m having trouble. I can’t even find the file test/mmultiplemice.cxx in fltk versions 1.1, 1.3 or 2.x :/

  • Benjamin Close said,

    That’s correct, MPX is now part of the standard build. In regards to the multiplemice test, it’s in the patch linked in this article. Below is an except from the patch

    diff –git a/test/multiplemice.cxx b/test/multiplemice.cxx
    new file mode 100644
    index 0000000..ed38c1f
    — /dev/null
    +++ b/test/multiplemice.cxx
    @@ -0,0 +1,99 @@
    +//
    +// “$Id$”
    +//
    +// Another forms test program for the Fast Light Tool Kit (FLTK).
    +//
    +// Modified to have 2 cubes to test multiple OpenGL contexts
    +//
    +// Copyright 2008 by Benjamin Close
    +//
    +// This library is free software; you can redistribute it and/or
    +// modify it under the terms of the GNU Library General Public
    +// License as published by the Free Software Foundation; either
    +// version 2 of the License, or (at your option) any later version.
    +//

Add A Comment

*