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

Bug 305696

Summary: Eclipse editor losing keyboard shortcuts focus after autocompletion
Product: [Eclipse Project] Platform Reporter: ppdkseth222
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: eclipse.felipe, ericwill, gheorghe, pwebster, remy.suen
Version: 3.5Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:
Attachments:
Description Flags
Proposed workaround none

Description ppdkseth222 CLA 2010-03-12 10:50:35 EST
On a java editor, when i use autocomplete and then select one suggestion from the popup window (by double clicking the mouse on the suggestion) the suggestion will be completed on the source code as it should but after this operation, the specific editor window can't receive any keyboard shortcuts.

Note that:
1. It is only the keyboard shortcuts that doesn't work when this happens, normal text input is not affected.
2. It only happens if i choose the entry by using the mouse. If i use the keyboard instead it won't happen.
3. If instead of choosing an autocomplete suggestion by using the mouse, i click somewhere outside the autocomplete popup window, there is no issue either.
4. When this bug happens, the tab of the specific editor has the color of an unfocused tab.
5. The keyboard shortcut focus can be fixed by clicking the window manager's titlebar which however doesn't look like it had lost focus earlier on. This operation also fixes the color of the eclipse editor's tab so it looks like a focused editor.

I am using Debian Linux squeeze/sid, Eclipse 3.5 with SWT, IceWM on click-to-focus mode. I had tried other window managers as well but i still got the same behavior on Eclipse.
Comment 1 Paul Webster CLA 2010-03-12 12:36:54 EST
(In reply to comment #0)
> 5. The keyboard shortcut focus can be fixed by clicking the window manager's
> titlebar which however doesn't look like it had lost focus earlier on. This
> operation also fixes the color of the eclipse editor's tab so it looks like a
> focused editor.

This sounds like a shell and widget activation event problem

> 
> I am using Debian Linux squeeze/sid, 

Which version of GTK+ is installed in this distro?  There are some well known problems with 2.18.x interactions with eclipse.

PW
Comment 2 ppdkseth222 CLA 2010-03-15 06:07:43 EDT
I forgot to mention that i have a "fix" already applied for another UI problem i had with the buttons. Many buttons wouldn't react to mouse interaction and after a search i did on the web i found that i needed this environmental variable exported prior to Eclipse running: GDK_NATIVE_WINDOWS=1. However the issue with keyboard shortcut focus existed prior to this.

The GTK version is 2.18.6-1. I just checked libgtk's website and it seems that 2.18.x is really their stable release, and it sounds very tricky to me to change to a different version, cause 2.19 would be their development/experimental and 2.16 is old which means it would only be the default version on some old distribution. Yes, on my previous Linux installation - Mandrake 9.2 - i didn't had that problem, but that distro came out at 2003.
Comment 3 Paul Webster CLA 2010-03-15 07:54:19 EDT
GDK_NATIVE_WINDOWS=1 is the only fix I know.  Passing to SWT for comment.  The Platform is listening on SWT.KeyDown events, but it sounds like the window isn't getting focus after the code completion.

PW
Comment 4 ppdkseth222 CLA 2010-03-16 11:47:27 EDT
I reproduced the bug on Ubuntu Linux 9.10 (Karmic Koala), which is using GTK 2.18.3-1, and its included Eclipse package (Version: 3.5.1 Build id: M20090917-0800).

I also reproduced the bug on the above Linux installation and Eclipse 3.5.2
Build id: M20100211-1343, for both GDK_NATIVE_WINDOWS=true and GDK_NATIVE_WINDOWS=false

Finally, i reproduced the bug on the above Linux installation and Eclipse 3.6M6 (Version: 3.6.0 Build id: I20100312-1448), for both GDK_NATIVE_WINDOWS=true and GDK_NATIVE_WINDOWS=false
Comment 5 ppdkseth222 CLA 2010-03-17 13:35:43 EDT
I noticed that i get similar behavior on another case - when i focus on a popup (other than the code completion one) by clicking in its area or by pressing the F2 key and then exit it by pressing ESC.
However if after focusing it but before pressing ESC i traverse the popup's window border once with the mouse, without clicking anywhere, and then press ESC the bug won't happen. 

With the above knowledge i returned to my original case and found out this:
If i press ctrl+space, move the mouse inside the code completion area, click *once* (which makes the popup take focus and the editor losing it), then traverse the popup's window border, then re-enter it and double click some completion entry, the bug won't happen.
Comment 6 ppdkseth222 CLA 2010-05-10 12:34:40 EDT
I had a look at the source code and from my very little understanding of how all
this works, i think the issue is somewhere here:

class: org.eclipse.swt.widgets.Shell
method: void bringToTop (boolean force) 

This method uses an X11 call when the widget has style SWT.ON_TOP,
but when it doesn't have that style it uses a GTK call. 

Now this issue appears between the Editor which as far as i have found
doesn't use the SWT.ON_TOP style and popup windows which use that style.

My guess is that we ask first the X11 to focus the popup without telling anything to the GTK,
and a bit later when we dispose that popup we ask the GTK to focus on the Editor, which 
though is the widget that GTK thinks the focus is applied already so maybe they implemented
some kind of optimization on 2.18 GTK in order to ignore this kind of call. 

I have no idea how to fix this properly cause there are more bugfixes in this piece of code.
Comment 7 ppdkseth222 CLA 2010-10-13 07:19:51 EDT
Created attachment 180752 [details]
Proposed workaround

This is my proposed workaround around this issue.
I 'll try increasing the priority in order to get a review from the maintainers.
Comment 8 Felipe Heidrich CLA 2010-10-13 09:31:47 EDT
Hey Bog, can you check this problem for us ?
Comment 9 Eric Williams CLA 2018-06-15 15:02:03 EDT
I cannot reproduce this issue, please file a new ticket against 4.8 if the issue reoccurs on GTK3.22.