Bug 562774 - [GTK] After replacing gdk_screen_get_active_window Display#post sends events to withdrawn windows
Summary: [GTK] After replacing gdk_screen_get_active_window Display#post sends events ...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.10   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.16 M3   Edit
Assignee: Alexander Kurtakov CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2020-05-04 07:40 EDT by Al Bundy CLA
Modified: 2020-05-15 06:16 EDT (History)
7 users (show)

See Also:


Attachments
test-project (6.40 MB, application/zip)
2020-05-04 07:40 EDT, Al Bundy CLA
no flags Details
patch (2.32 KB, patch)
2020-05-05 07:52 EDT, Al Bundy CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Al Bundy CLA 2020-05-04 07:40:15 EDT
Created attachment 282685 [details]
test-project

We are using Display#post for years for nigthly tests of our swt-application.

currently we are using RCP 3.8 and 4.7 which works as expected.

Some days ago I thougth I give the latest RCP release a chance and switched one of our test-projects to RCP 4.15.

But with this version some of our tests are failing because the input is not working.

So I've tried to create a small test-project (see attachment).

It least I found out that the change was introduced from SWT 108 to 109

If you add the project to your workspace and add the libraries from 108 to your class path you will set that all three columns will be edited.

If you remove the 108-libs and add the 109-libs you will see that after the ComboBoxCellEditor was opened none of the inputs are received by the next editors. :-(
Using newer jface from 109 with swt from 108 works also as expected - so this have to be an swt-issue.

At least in my ubuntu-vm I had to use the mouse-wheel while the test is running.
--> but this seems to be a local issue because in our nightly tests there is nobody that uses that mouse-wheel.
Comment 1 Andrey Loskutov CLA 2020-05-04 10:17:37 EDT
(In reply to Al Bundy from comment #0)
> It least I found out that the change was introduced from SWT 108 to 109

So we are speaking about Eclipse 4.10 release where it was broken.
If you could bisect it to a commit, it would be helpful.
Comment 2 Al Bundy CLA 2020-05-04 11:42:54 EDT
What I can say for now:
this happens not on windows - there everything is working as expected also in 4.15
maybe this is an issue with the ComboBoxCellEditor because we have only this issue if such an editor was opened.

I can checkout swt and try to find a revision that introduced the bug.
Comment 3 Al Bundy CLA 2020-05-05 06:33:21 EDT
Ok - I've checked out swt and binaries from github and after the project was setup I could search for the change...

It seems that this issue was introduced with

commit c20eead8e2a8bedbacf2c2f44242056ae1f344de
Author: Xi Yan <xixiyan@redhat.com> 2018-09-28 08:20:20
Committer: Xi Yan <xixiyan@redhat.com> 2018-10-02 06:34:15
Parent: b0c7620b71598cfad1daed3cde1f91d6b5232d16 (v4922r15)
Branches: master, origin/master

Bug 518714 - [GTK3] Replace deprecated gdk_screen_get_active_window()

Remove gdk_screen_get_active_window, replace it by iterating the window
stack and getting the current focused window as the active window.

Change-Id: Ia80b195152c7754072a8a86efc2848460468b05f
Signed-off-by: Xi Yan <xixiyan@redhat.com>



If I checkout this revision I have to make a small change in Display.java at line 4425 from
          long /*int*/ gdkScreen = GDK.gdk_screen_get_default();
          long /*int*/ gdkWindow = 0;
          long /*int*/ window_list = GDK.gdk_screen_get_window_stack(gdkScreen);
to
          long gdkWindow = GDK.gdk_get_default_root_window();
          long window_list = GDK.gdk_window_get_children(gdkWindow);
This change is already in the master branch and seems to be necessary at least on latest ubuntu.

If I revert c20eead8e2a8bedbacf2c2f44242056ae1f344de or go back to the previous commit my test works as expected.

Maybe this has something to do with the open list in the celleditor.
Comment 4 Al Bundy CLA 2020-05-05 07:35:08 EDT
I played around with Display.java and removed the break in the post-method while searching the active window.
With the removed break my test works.

After that I did some checks and printed the state of found windows and found out that the state for the wrong window looks like this 10100001 and for the correct window like this 10100000

According to https://developer.gimp.org/api/2.0/gdk/gdk-Event-Structures.html#GdkWindowState the lsb seems to be GDK_WINDOW_STATE_WITHDRAWN

I think the loop should check 

if ((state & GDK.GDK_WINDOW_STATE_FOCUSED) != 0
  && (state & GDK.GDK_WINDOW_STATE_WITHDRAWN) == 0)


At least my test works with this change as expected.
Comment 5 Andrey Loskutov CLA 2020-05-05 07:36:56 EDT
(In reply to Al Bundy from comment #4)
> I played around with Display.java and removed the break in the post-method
> while searching the active window.
> With the removed break my test works.
> 
> After that I did some checks and printed the state of found windows and
> found out that the state for the wrong window looks like this 10100001 and
> for the correct window like this 10100000
> 
> According to
> https://developer.gimp.org/api/2.0/gdk/gdk-Event-Structures.
> html#GdkWindowState the lsb seems to be GDK_WINDOW_STATE_WITHDRAWN
> 
> I think the loop should check 
> 
> if ((state & GDK.GDK_WINDOW_STATE_FOCUSED) != 0
>   && (state & GDK.GDK_WINDOW_STATE_WITHDRAWN) == 0)
> 
> 
> At least my test works with this change as expected.

Many thanks for bisecting & patch proposal. Could you please push it to Gerrit?
Comment 6 Al Bundy CLA 2020-05-05 07:41:43 EDT
I have no idea how to do this.
I've checked out the master branch from https://github.com/eclipse/eclipse.platform.swt/

I can fork the project and create a branch if you want.
Or should I do something different?
Comment 7 Al Bundy CLA 2020-05-05 07:52:35 EDT
Created attachment 282704 [details]
patch

I've attached a patch (created with eclipse).
Maye you can use this.
Comment 8 Andrey Loskutov CLA 2020-05-05 07:55:46 EDT
(In reply to Al Bundy from comment #7)
> Created attachment 282704 [details]
> patch
> 
> I've attached a patch (created with eclipse).
> Maye you can use this.

@Al Bundy: please sign ECA (click on your rot ECA badge and follow instructions).
I believe we can't accept patches without ECA signed.
See also https://wiki.eclipse.org/Platform/How_to_Contribute
Comment 9 Al Bundy CLA 2020-05-05 08:06:24 EDT
To be honest I haven't read the ECA and don't have the time to do this yet.

This is just a small bugfix and not a fancy new feature - so at least in my opinion this should be no problem.

Maybe xixiyan@redhat.com can have a look at this patch because he has implemented the new function.
Comment 10 Andrey Loskutov CLA 2020-05-05 08:21:40 EDT
(In reply to Al Bundy from comment #9)
> To be honest I haven't read the ECA and don't have the time to do this yet.
> 
> This is just a small bugfix and not a fancy new feature - so at least in my
> opinion this should be no problem.

I'm not a lawyer, can't say for sure. ECA FAQ https://www.eclipse.org/legal/ecafaq.php says:

8. What happens if I don't sign the ECA?
Nothing, except you won't be allowed to contribute to open source projects at Eclipse.

If I would accept the patch, it would be your contribution to SWT and without ECA it is not allowed to be merged.

> Maybe xixiyan@redhat.com can have a look at this patch because he has
> implemented the new function.

Xi is not working on SWT anymore.
Comment 11 Al Bundy CLA 2020-05-05 08:50:51 EDT
I totally understand this but I created only the bugreport and wanted to help to identify the issue.

I'm not a gtk-expert so maybe akurtako@redhat.com, sravankumarl@in.ibm.com,  nikita@nemkin.ru or ericwill@redhat.com can have a look at this patch because all of them commited into the gtk-parts of the swt-project in the last 6 months.
Comment 12 Al Bundy CLA 2020-05-09 07:58:06 EDT
I've added the mails akurtako@redhat.com, sravankumarl@in.ibm.com,  nikita@nemkin.ru, ericwill@redhat.com to the cc list - hopefully they get an information and will have a look at this issue.
Comment 13 Al Bundy CLA 2020-05-12 02:01:25 EDT
@Andrey Loskutov: According to the "Developer's Certificate of Origin 1.1" from ECA I can certify that
"The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file"
In this case it's just a bugfix so there should be no licensing issues.

And if I understand correctly you should be able to use the patch because of question c
"The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it."
Comment 14 Al Bundy CLA 2020-05-12 02:12:40 EDT
I've modified the title to describe the issue better.

As an example for this issue:
create a table with at least two columns where the first column uses a ComboBoxCellEditor and the second a TextCellEditor.

Now if you programmatically send events with Display#post to the table to open the editors and select entries or type text, from the moment the ComboBoxCellEditor was openened all events are send to the hidden list of the ComboBoxCellEditor even if the TextCellEditor has the focus.

After tracking this down it seems that it is not enough to check the focuesed state in Display#post it must also be checked if the window is withdrawn.

With this additional check the correct Widget receives the events.
Comment 15 Eclipse Genie CLA 2020-05-13 07:18:06 EDT
New Gerrit change created: https://git.eclipse.org/r/162951
Comment 16 Alexander Kurtakov CLA 2020-05-13 07:33:03 EDT
(In reply to Eclipse Genie from comment #15)
> New Gerrit change created: https://git.eclipse.org/r/162951

This seems to fix the issue.
Comment 18 Alexander Kurtakov CLA 2020-05-13 08:17:28 EDT
Al Bundy, thanks for the investigations. Should be fixed in tomorrow's I-build please test and give feedback here.
Comment 19 Al Bundy CLA 2020-05-13 08:28:34 EDT
@Alexander Kurtakov: Thank you very much - I'll test this as soon as the I-build is available
Comment 20 Al Bundy CLA 2020-05-15 06:16:25 EDT
Works perfect :-)