Stevo14's picture

Mouse click events in Linux

It seems as though mouse events are not being triggered in my application although I don't know why this would be. I hook the events at the beginning of the application like this:

Mouse.ButtonDown += OnMouseDown;
Mouse.ButtonUp += OnMouseUp;

Am I missing something? Do I need to call ProcessEvents() inside OnUpdateFrame() ?

AttachmentSize
debug.log3.41 KB

Comments

Comment viewing options

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

There shouldn't be a need to call ProcessEvents manually. Sounds like a bug.

A couple of questions:

a) which version are you using?

b) if it is 0.9.0 or higher, can you try the following?

Run Examples.exe, and press Ctrl+F1. Some new samples should show up, including one that reads "Test: Input Logger". Execute that, and select the "Mouse" tab from in the window that appears. Move your mouse over the small window - does it report its position? Click. Is the event reported?

Stevo14's picture

a) I'm using 9.0

b)I couldn't get Ctrl+F1 to work in the regular Examples.exe but I ran the input logger test from a day-old subversion copy and the mouse behaves just like in my application, the position gets reported but click events and delta times for the scroll wheel are missing.

If you need me to I can boot into windows and test things there.

the Fiddler's picture

I just tested on Windows, and it works.

Ok, I'll need some more information on your system:

a) build a debug version of OpenTK SVN, run a few examples from Example.exe (make sure to press some mouse buttons!) and attach the debug.log file here.

b) Do Examples.exe report any error information to the console? We are looking for X errors, which look like BadMatch, BadWindow etc.

c) which Linux distribution/version and which Mono version is this?

Stevo14's picture

a/b) I built a debug version from svn and tried a few examples.

The Input Logger would not run. Error:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
  at OpenTK.GameWindow.get_MustResize () [0x00000] 
  at OpenTK.GameWindow.OnLoadInternal (System.EventArgs e) [0x00000] 
  at OpenTK.GameWindow.Run (Double updates_per_second, Double frames_per_second) [0x00000] 
  at Examples.Tests.S04_Input_Logger.LaunchGameWindow () [0x00000] 
  at (wrapper delegate-invoke) System.MulticastDelegate:invoke_void ()

Simple Window ran fine but when I closed the window I got this error:

Destroy event fired from window: X11.WindowInfo: Display 140989856, Screen 0, Handle 65011714, Parent: (null)
Restoring priority.
X11GLNative shutdown sequence initiated.
UnmapNotify event was not handled
X11 window 65011714 destroyed.
X11 Error encountered: 
  Error: GLXBadCurrentWindow
  Request:     148 (5)
  Resource ID: 0x3E00002
  Serial:      27804
  Hwnd:        <null>
  Control:     <null>   at System.Environment.get_StackTrace()
   at System.Windows.Forms.XplatUIX11.HandleError(IntPtr display, XErrorEvent ByRef error_event)
   at System.Windows.Forms.XplatUIX11.HandleError(IntPtr , XErrorEvent ByRef )
   at OpenTK.Platform.X11.Glx.MakeCurrent(IntPtr , IntPtr , IntPtr )
   at OpenTK.Platform.X11.Glx.MakeCurrent(IntPtr , IntPtr , IntPtr )
   at OpenTK.Platform.X11.X11GLContext.Dispose(Boolean manuallyCalled)
   at OpenTK.Platform.X11.X11GLContext.Dispose()
   at OpenTK.GameWindow.Dispose(Boolean manual)
   at OpenTK.GameWindow.Dispose()
   at Examples.Tutorial.T01_Simple_Window.Main()
   at System.Reflection.MonoMethod.InternalInvoke(System.Object , System.Object[] )
   at System.Reflection.MonoMethod.InternalInvoke(System.Object , System.Object[] )
   at System.Reflection.MonoMethod.Invoke(System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(System.Object obj, System.Object[] parameters)
   at Examples.ExampleLauncher.RunExample()
   at Examples.ExampleLauncher.runButton_Click(System.Object sender, System.EventArgs e)
   at System.Windows.Forms.Control.OnClick(System.EventArgs e)
   at System.Windows.Forms.Button.OnClick(System.EventArgs e)
   at System.Windows.Forms.ButtonBase.OnMouseUp(System.Windows.Forms.MouseEventArgs mevent)
   at System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs e)
   at System.Windows.Forms.Control.WmLButtonUp(Message ByRef m)
   at System.Windows.Forms.Control.WndProc(Message ByRef m)
   at System.Windows.Forms.ButtonBase.WndProc(Message ByRef m)
   at System.Windows.Forms.Button.WndProc(Message ByRef m)
   at System.Windows.Forms.Control+ControlWindowTarget.OnMessage(Message ByRef m)
   at System.Windows.Forms.Control+ControlNativeWindow.WndProc(Message ByRef m)
   at System.Windows.Forms.NativeWindow.WndProc(IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.XplatUIX11.DispatchMessage(MSG ByRef msg)
   at System.Windows.Forms.XplatUI.DispatchMessage(MSG ByRef msg)
   at System.Windows.Forms.Application.RunLoop(Boolean Modal, System.Windows.Forms.ApplicationContext context)
   at System.Windows.Forms.Application.Run(System.Windows.Forms.ApplicationContext context)
   at System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm)
   at Examples.ExampleLauncher.Main()

c) Ubuntu 7.10; "mono --version" reports "Mono JIT compiler version 1.2.6 (tarball)"

the Fiddler's picture

Thanks, fixed the first issue.

Can you please update from SVN and try Input Logger again? A debug.log file should be generated in the same folder - can you please attach that to the opening post (just edit it), after you run the Input Logger? It should contain information useful for debugging.

Edit: Ok, confirmed the issue. The strange thing it that a button event is reported if you press two keys at once. The stranger thing is that (I'm sure!) it worked just prior to the 0.9.0 release.

In any case I'll work on a fix during the weekend, the issue probably lies at the event handling code in Source/OpenTK/Platform/X11/X11Input.cs or X11Mouse.cs

Stevo14's picture

Log attached.
I also figured something out while doing some test clicks for the log file. Click events are raised if (and only if) two mouse buttons are pressed. For example, if I click the left mouse button, nothing happens. If I then leave the left button down and press, say, the right mouse button, the click event is raised for the first button that was pressed (left in this case). The same goes if the middle button is pressed first and then the left mouse button. (The click event is raised for the middle button only after pressing the left button.) The behavior is rather strange, but it is atleast consistent. :)

EDIT: You beat me to the post.

the Fiddler's picture

Alright, fixed as of revision 1100 :)

Thanks for the bug-report!

Stevo14's picture

No problem. Thanks for the fix!