Skip to content

Windows Mouse Lock and Wiring Up nsIWidget

November 23, 2011

So, with Humph showing me nsEventStateManager, a lightbulb went off in my head. nsEventStateManager::GenerateMouseEnterExit(aEvent) takes an nsGUIEvent* as its parameter. nsGUIEvent has a widget attached to it. We can get the widget now. Then I found out about nsFocusManager::GetFocusManager()->GetFocusedWindow(ptr), which gives you the nsIDOMWindow currently in focus. Great! Now I can keep going down the tree until I find my MouseLockable instance. Then, all I need to do to tell the widget that mouse lock is now on is to set a boolean in it. Now that the nsIWidget (nsWindow is one), knows that its mouse lock is on or off, it can do OS-Specific code for it, as described a few posts back.

(In GenerateMouseEnterExit(aEvent)) http://pastebin.com/pt0u2vdr

I also ran into a little bug with the DOM’s movement deltas when centering the mouse cursor every mouse move while in mouse lock. (it kept reporting opposite values). The solution was actually simple. Just report the last mouse position value as width/2, height/2, just like what I set the cursor too. If it’s anything but that, it must have moved from the center.

No clue if anything is in the right place of course. But it feels great to have some stuff actually working.

Time to test this with some games!

From → Open Source

Leave a Comment

Leave a comment