Re: How to capture mouse movements independend of a Window?



tomas tuxteam de wrote:
Yo! hope you started well the new year.

Good new year to you too.

But the main problem remains: Once the pointer (Pirate!!) touch the border
or the window, the mouse coordinate don't change anymore.

Well, that's what the fourth argument of GdkPointerGrab is for. If you
pass in a (pointer to a) GdkWindow, then the cursor is confined to the
window. If you pass in NULL, it'll allowed to move freely (I haven't
tested whether the X root window limits its movements: this might bite
you).

I should have RTFM more attentive. With the fourth argument set as you
suggested it works. And as you worried, the X root window still limits
the cursor movement. See below for my workaround.

Maybe there is a function to place the cursor in the middle of the window?

You might move the pointer with gdk_display_warp_pointer() after each
received movement event.

Yes, that's the function I need. (but move it each time is not a good idea)

Ok, I claim the problem is mostly solved. The solution is not very
beautiful, but at least it works - even with PyGTK alone:

When the Short-Cut key is pressed, the position of the pointer is stored.
Then the pointer is grabbed and the cursor is set to invisible.
Now all the motion events are captured. I use a rectangle with about 100px
space to the root window border. If the cursor is not within this frame,
the cursor is set to the center of the screen. This reduce the number of
warp_pointer() calls (each time warp_pointer() is used it generates a
motion event). Then the user decide to leave this mode and press the
short-cut again*, the pointer is ungrabbed and the cursor automatically
restored. Then I use warp_pointer() again to place the pointer at the
position the mode was entered before.

* It's better to leave the mode after a mouse-click too. Users who don't
know how to leave the pointer grab may click if they don't see the mouse.

Thank you for the help, Tomas.

Cheers, Andy



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]