Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 521506

Summary: [GTK] pure gdk implementation in Display.post(Event) does not work for menu items
Product: [Eclipse Project] Platform Reporter: Michael Seele <mseele>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: akurtakov, ericwill, xixiyan
Version: 4.7Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/132225
Whiteboard:
Attachments:
Description Flags
Snippet none

Description Michael Seele CLA 2017-08-29 03:55:03 EDT
Created attachment 270004 [details]
Snippet

In https://bugs.eclipse.org/bugs/show_bug.cgi?id=505338 the mouse click implementation of Display.post(Event) has been changed from OS.XTestFakeButtonEvent to pure gdk implementation (OS.gdk_test_simulate_button). This breaks clicking on menu items. 

If you run the attached snippet with SWT-4.7M2 (before the change) the snippet prints out the expected output:

TEST BUTTON CLICKED
ITEM CLICKED

If you run the attached snippet with anything newer than SWT-4.7M2 (e.g. SWT-4.7) the menu item is not clicked anymore. The output it only:

TEST BUTTON CLICKED

Expected behaviour should be clicking on the Button and the Menu Item.

This has been tested under

CentOS Linux release 7.3.1611 (Core) 
GTK 3.14.13
Comment 1 Eric Williams CLA 2018-03-28 11:20:23 EDT
I can reproduce this on GTK3.22, 4.8 M6, and Fedora 27.
Comment 2 Michael Seele CLA 2018-11-08 09:14:58 EST
Now it's even worse: 

Under SWT S-4.10M1-201810101800 there is no "TEST BUTTON CLICKED" and no "ITEM CLICKED" output.

So no click works with the "new" OS.gdk_test_simulate_button.
Is there anybody who looks into this? For us it's a real showstopper :(
Comment 3 Alexander Kurtakov CLA 2018-11-08 09:16:47 EST
Xi, please investigate.
Comment 4 Eclipse Genie CLA 2018-11-09 15:14:29 EST
New Gerrit change created: https://git.eclipse.org/r/132225
Comment 5 Xi Yan CLA 2018-11-09 15:47:17 EST
(In reply to Eclipse Genie from comment #4)
> New Gerrit change created: https://git.eclipse.org/r/132225

After some investigation, I found that: 

1) For GTK3.14 and below, using gdk_test_simulate_button the snippet will output only "TEST BUTTON CLICKED" as when the bug was first reported. After GTK3.16, there is no "TEST BUTTON CLICKED" output and no "ITEM CLICKED" output. So I did a git bisect and found that this GTK commit broke the receiving of clicked signal for simulated button events: 

https://gitlab.gnome.org/GNOME/gtk/commit/a4e0de183967d51f5ef7ec602f96ad6c33456701

It looks like for some reason, simulated button release invokes the cancel callback which does not emit a "clicked" signal, and hence the gtk_clicked method does not get invoked on the SWT side which means no SWT.Selection event are sent. 

2) The same behaviour happens with a native GTK snippet, no callback is invoked on button "clicked" signal when using gdk_test_simulate_button to fake the mouse click. 

3) Replacing the gdk_test_simulate_button with the XSendEvent API also does not emit the signals since gdk_test_simulate_button is implemented using XSendEvent on the GTK level. However, I noticed that these method does indeed "clicks" the button and menu since the button shows visually it is being clicked and the menu bar is opened, but since no signals are sent, it doesn't makes sense to use them. 

4) By occasion, I noticed that using XSelectInput to request the X server to report ButtonPressedMask event (which was being used by the implementation of gdk_test_simulate_button) makes the "clicked" signal sent again for the Button widget. (i.e. we are back to the behaviour in GTK3.14..). See the patch attached. But this still does not fix the issue with menu items. 

Since gdk_test_* API are removed in GTK4, I think it maybe makes more sense to use the old XTestFakeButtonEvent to deal with this bug.
Comment 6 Alexander Kurtakov CLA 2018-11-09 15:54:51 EST
(In reply to Xi Yan from comment #5)
> (In reply to Eclipse Genie from comment #4)
> > New Gerrit change created: https://git.eclipse.org/r/132225
> 
> After some investigation, I found that: 
> 
> 1) For GTK3.14 and below, using gdk_test_simulate_button the snippet will
> output only "TEST BUTTON CLICKED" as when the bug was first reported. After
> GTK3.16, there is no "TEST BUTTON CLICKED" output and no "ITEM CLICKED"
> output. So I did a git bisect and found that this GTK commit broke the
> receiving of clicked signal for simulated button events: 
> 
> https://gitlab.gnome.org/GNOME/gtk/commit/
> a4e0de183967d51f5ef7ec602f96ad6c33456701
> 
> It looks like for some reason, simulated button release invokes the cancel
> callback which does not emit a "clicked" signal, and hence the gtk_clicked
> method does not get invoked on the SWT side which means no SWT.Selection
> event are sent. 
> 
> 2) The same behaviour happens with a native GTK snippet, no callback is
> invoked on button "clicked" signal when using gdk_test_simulate_button to
> fake the mouse click. 
> 
> 3) Replacing the gdk_test_simulate_button with the XSendEvent API also does
> not emit the signals since gdk_test_simulate_button is implemented using
> XSendEvent on the GTK level. However, I noticed that these method does
> indeed "clicks" the button and menu since the button shows visually it is
> being clicked and the menu bar is opened, but since no signals are sent, it
> doesn't makes sense to use them. 
> 
> 4) By occasion, I noticed that using XSelectInput to request the X server to
> report ButtonPressedMask event (which was being used by the implementation
> of gdk_test_simulate_button) makes the "clicked" signal sent again for the
> Button widget. (i.e. we are back to the behaviour in GTK3.14..). See the
> patch attached. But this still does not fix the issue with menu items. 
> 
> Since gdk_test_* API are removed in GTK4, I think it maybe makes more sense
> to use the old XTestFakeButtonEvent to deal with this bug.

Using XTest is not an option on Wayland which is more and more the default.
Comment 7 Michael Seele CLA 2018-11-12 01:17:00 EST
> Using XTest is not an option on Wayland which is more and more the default.

Why not supporting both, depending on the gtk version (or if wayland is used)?
Comment 8 Alexander Kurtakov CLA 2018-11-13 09:23:43 EST
(In reply to Michael Seele from comment #7)
> > Using XTest is not an option on Wayland which is more and more the default.
> 
> Why not supporting both, depending on the gtk version (or if wayland is
> used)?

I'm not sure this is feasible especially if someone runs eclipse under wayland via XWayland, in which case there will be X11 but with some of the wayland security constraints thus XTest might work or not (to be tested) but definetely not easy to handle as there is no way to detect running under XWayland AFAIK.
Comment 9 Xi Yan CLA 2018-11-13 11:25:57 EST
XTest does not work on Wayland. In fact, I don't think Wayland supports simulating any key or mouse events due to security constraints. gdk_test_* methods are also implemented for X11 only. I'm not sure if we can generate any low level keyboard and mouse events on Wayland at all.
Comment 10 Xi Yan CLA 2018-12-07 11:11:15 EST

*** This bug has been marked as a duplicate of bug 540809 ***