• Immutable Page
  • Info
  • Attachments


class MousePoller

        typedef boost::function<void (const CompPoint &)> CallBack;

        MousePoller ();
        ~MousePoller ();

        setCallback (CallBack callback);

        start ();

        stop ();

        active ();

        getPosition ();

        static CompPoint
        getCurrentPosition ();

    friend class MousepollScreen;

Creating the callback function

MousePoller is modeled off of CompTimer, in that for each update, there is a callback function executed for all interested clients. The callback function must be prototyped as follows (either static or normal):

FooClass::positionUpdate (const CompPoint &p)

Once you have implemented this function in the class which you wish to have the callback inside of, then you can bind it to the MousePoller class with setCallback () normally if the function is static, or you can use boost::bind to bind it to a class object. When ::start () is called, the function will be called each time a new position is retrieved until you call ::stop ()

Getting the current mouse position synchronously

In some cases, you will not be able to wait until the next position is fetched by MousePoller and handed to your callback function, and you will need to know the current position of the mouse co-ordinates before your next section of code executes. There are two functions for this. You can use ::getPosition () which returns a CompPoint of the current buffered position that the MousePoller last retrieved. Note that in this case, the MousePoller must have been active at some point during the past, or must be active now, but in-between timeouts. Also note in this case that the position returned is the last retrieved cursor position (either through the timeout or getCurrentPosition), and as such may not be accurate.

If you require an accurate position of the mouse, there is also the static ::getCurrentPosition function, which will retrieve the current position from the X Server. This means a round-trip to the server though, and is expensive. As such, if you don't require the position straight away or can work with a slightly older position, it is recommended to use getPosition instead.

Development/zero-nine/PluginsClasses/Mousepoll (last edited 2010-10-19 10:56:28 by 130)