Possible to get mouse click when a pop-up (menu, popover, drop-down, etc) is open?

It seems that on Windows, if there is some sort of pop-up element, such as a context menu, open, and the user clicks your control (or widget), the pop-up element gets closed and you get the mouse click event. However, on Linux, the pop-up element gets closed and you DO NOT get the mouse click event.

I am using GTK (GTK#) to create a cross-platform GUI application, and it seems that GTK works like Linux even on Windows. I want my app to work like other Windows applications on Windows. Is there any way to get the mouse click event on Windows, in the situation described above?

I mean, not in a very complex and laborious way, like modifying GTK itself. If it can only be achieved through such a method, I will give up.

If it is not practically possible, please let me know of that.

You could try to send a message with SendMessage and WM_LBUTTONDOWN from the appropriate GTK event handler (closing pop-up element or mouse clicks). However, this is an idea only.

It is not that pop-up elements closed → my widgets get a mouse click event. It is only when the pop-up was closed because the user has clicked those widget. For example, if I have a TreeView and Button1 and Button2, and TreeView is showing its context menu, and the user clicked Button2. In this case I have to somehow send mouse click event from TreeView’s pop-up close event to Button2? Handling all such cases seems too complex, and I am not even sure if I can get the mouse click position when any pop-up element (such as a drop-down) is closed.

I thought about capturing the mouse Win32 events from the GtkWindow itself (seems like all Gtk widgets are just graphics, not actual Win32 windows, unlike Win32 apps. I ran Spy++ and try to capture Win32 event of the GtkWindow. I could get mouse events until I opened a pop-up element. Then it could not get any mouse events. When I clicked some where on the GtkWindow and the pop-up element was closed, it got WM_MOUSEMOVE and WM_SETCURSO, but not a mouse button event. My guess is that a pop-up element is a Win32 window and it is capturing the mouse? I wanted to “spy” that pop-up element, but if I click Spy++ to set the spying target to that pop-up element, it closed itself, so I could not do that. Maybe I could try to capture the Win32 events of the pop-up elements using code, but I wished there was an easier way than this.

It seems that you know about how GTK works on Windows much more than me :slight_smile:

Nevertheless, one more idea. At least, you can try to check, whether the approach with sending a message works in general. Obtain the window handle to the window, which must be activated after the pop-up element is closed, while this is focused/active. Then try to send/post a WM_LBUTTONDOWN message by using this handle from an appropriate location while a pop-up element is closing. For this experiment, you can use any coordinates that are valid in any case (e.g. 0, 0). If it works, then it makes sense to try and solve other parts of the puzzle. If not, then you need another approach.

I think this is how GTK works by design. While a pop-up element (e.g. a floating menu) is opened the main window does not get motion-notify-events, and probably no other public events.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.