Chris The Avatar's picture

Mouse Handeling on Linux

Thank you for reading this in advance. Currently myself of one user and myself are having issues with our cursor on Linux. When attempting to leave the game window, the cursor resets back to the center of the window. This only happens on Linux and not on Windows. Mouse handling code is shown below:

Are there any work arounds/fixes for this; is it a known issue? (Currently using OpenTK 1.1)

  void Mouse_Move(object sender, OpenTK.Input.MouseMoveEventArgs e)
            {
 
                mouseX = e.X;
                mouseY = e.Y;
                if (e.X <= 0 || e.Y <= 0 || e.X >= ClientRectangle.Width - 1 || e.Y >= ClientRectangle.Height - 1)
                {
                    CursorVisible = true;
                }
                else
                {
                    if (inWin)
                        CursorVisible = false;
                }
            }
            protected override void OnFocusedChanged(EventArgs e)
            {
                if (Focused)
                    inWin = true;
                else
                    inWin = false;
                FRO.Client.Input.Keyboard.ResetKeyboardStates();
            }
            protected override void OnMouseEnter(EventArgs e)
            {
                if (inWin)
                    CursorVisible = false;
            }

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Which distro and desktop environment environment are you using?

Please file a bug report at https://github.com/opentk/opentk/issues

From the behavior you are describing (mouse resetting to center), it appears that OpenTK is falling back to the libX11 mouse driver instead of using the newer libXi implementation. Make sure you have an up-to-date OpenTK.dll.config (add it to your application and tick the "Copy to Output Directory" build option.)

Chris The Avatar's picture

without the config, I get a libXi not found exception... It works with the config, So you are right about it likely falling back to libX11. But should mouse handling not be supported in both if there is going to be a fallback? Im using Ubuntu 12.04 and the other user is using newer version of SuSE. libXi is not even in the apt-get list either.

I will enter an issue in a bit.

Thanks

Chris

the Fiddler's picture

Thanks for testing. libXi provides the Xinput2 extension and should be available out of the box since 2009-2010 or so. You simply need the correct dll.config in order to find the library.

The problem with libX11 is that it does not support relative mouse events. The only way is to hide the mouse cursor and reset the mouse position to the center of a window after every move. The issue you are seeing is probably caused by a race condition between the GameWindow making the cursor visible and the X11Mouse backend moving the cursor back to the center of the window.

This is probably fixable, so please file a bug.