ClearChain

Adding Multiple Mice Support to FLTK using MPX

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:

 

 

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.

Exit mobile version