Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 67979 - editor focus issue
Summary: editor focus issue
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux-GTK
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-21 06:48 EDT by Tom Hofmann CLA
Modified: 2013-08-03 01:23 EDT (History)
7 users (show)

See Also:


Attachments
before_popup.png (41.15 KB, image/png)
2004-06-21 11:13 EDT, Tom Hofmann CLA
no flags Details
with_popup.png (47.18 KB, image/png)
2004-06-21 11:19 EDT, Tom Hofmann CLA
no flags Details
My setup (167.30 KB, image/png)
2004-06-24 16:21 EDT, Billy Biggs CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Hofmann CLA 2004-06-21 06:48:48 EDT
3.0RC3

Not sure if this is related to bug 58642, bug 65985 or bug 65053, but they are
all fixed for RC3. 

Example copied from bug 57311 comment 12:

- Have this class:

class C {
    void m() {
        System.out.println();
    }
}

- caret on println
- press F2
-> popup
- press Esc 
-> popup goes away
-> editor quickly gains focus, but then looses it again
-> no keyboard focus, only the main menu works

I only marked this as critical because it seems to be an unfixed case of the
bugs noted above. On its own, this is major.
Comment 1 Douglas Pollock CLA 2004-06-21 09:46:56 EDT
I have tried to reproduce this problem but cannot.  Could you please 
double-check that this is happening in I200406192000? 
 
You are using GTK+ 2.2.1, right? 
Comment 2 Tom Hofmann CLA 2004-06-21 10:15:43 EDT
I keep forgetting...

$ rpm -q gtk+ gtk2 kdebase
gtk+-1.2.10-25
gtk2-2.2.1-4
kdebase-3.1-15

Yes, this is on I200406192000.
Comment 3 Tom Hofmann CLA 2004-06-21 10:17:30 EDT
Note that, other than bug 65053, left-clicking into the editor fixes the
problem. It really just looks like the focus is somwhere else (but Ctrl+Tab
won't help).
Comment 4 Billy Biggs CLA 2004-06-21 10:20:25 EDT
I can't reproduce it here on Gtk+ 2.2.1, 3.0-RC3.  For kicks, can you post a
screenshot of your setup?  Also, where is your mouse located when this happens?
Comment 5 Tom Hofmann CLA 2004-06-21 11:13:29 EDT
Created attachment 12570 [details]
before_popup.png

Shows screenshot with everything ok: caret in 'println'. The mouse cursor is
somewhere where where it will not interfere with the popup shown in the next
attachment, for example in the whitespace to the right of the package
statement.

To get the popup from this setup, press F2.
Comment 6 Tom Hofmann CLA 2004-06-21 11:19:00 EDT
Created attachment 12572 [details]
with_popup.png

Popup showing. The javadoc popup has the focus, you can scroll around etc,
which is fine (make sure you get the popup by pressing F2, not the mouse
hover). Note that the editor is grey, i.e. does not have the focus.

When pressing Esc in this situation, the popup will go away, but editor focus
is not restored. The focus is gone.

- Global menu bar works
- System key bindings (Alt+Tab etc.) work. Using Alt+Tab to switch applications
and back to eclipse brings back the focus.
Comment 7 Billy Biggs CLA 2004-06-21 11:28:15 EDT
OK, I can reproduce this easily now under kwin 0.95 / KDE 3.1-13 Red Hat.
Comment 8 Billy Biggs CLA 2004-06-21 11:40:26 EDT
When it occurs, Display.getActiveShell() and Display.getFocusControl() are both
null.  This may again be related to bug 65985.

To reproduce, you need to use KDE 3.1 and GTK+ 2.2, since Doug cannot reproduce
under KDE 3.2 and GTK+ 2.4.
Comment 9 Tom Hofmann CLA 2004-06-21 11:42:57 EDT
I just checked: we don't regularly dispose of the popup shell when it hides -
the shell is kept invisible and reused by the next popup. It is disposed when
the subject (=editor) is.

Pressing Esc however seems to dispose of the shell, since the internally used
StyledText translates the Esc key somehow (not sure about this one).
Comment 10 Tom Hofmann CLA 2004-06-21 11:45:49 EDT
> Pressing Esc however seems to dispose of the shell, since the internally used
> StyledText translates the Esc key somehow (not sure about this one).

This is wrong. DefaultInformationControl registers a keylistener with the
StyledText and disposes upon Esc (hardcoded).
Comment 11 Billy Biggs CLA 2004-06-21 11:51:42 EDT
Here is a log of what happens to shell.hasFocus when I hit ESC:

[key] activeShell = Shell {Java - C.java - Eclipse Platform}, focusControl =
StyledText {}
Shell.bringToTop() setting hasFocus = false
Shell.bringToTop() setting hasFocus = true
Shell.gtk_focus_out_event() setting hasFocus = false
Shell.gtk_focus_in_event() setting hasFocus = true
Shell.bringToTop() setting hasFocus = false
Shell.bringToTop() setting hasFocus = true
Shell.gtk_focus_in_event() setting hasFocus = true
Shell.gtk_focus_out_event() setting hasFocus = false

And now we are hosed.  Switching between windows corrects the problem.
Comment 12 Tom Hofmann CLA 2004-06-21 11:58:39 EDT
Here comes my debug trace:

# pressing F2:

KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode =
0x100000b, character = 0x0)
KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [F2, NUL])
KEYS >>> WorkbenchKeyboard.executeCommand(commandId =
'org.eclipse.jdt.ui.edit.text.java.show.javadoc')
KEYS >>>     value for 'id' attribute = null
KEYS >>>     value for 'enabled' attribute = true
KEYS >>>     executing 'org.eclipse.ui.commands.ActionHandler' (492445018)
CONTEXTS >>> [org.eclipse.ui.contexts.dialogAndWindow,
org.eclipse.ui.contexts.dialog, org.eclipse.jdt.ui.javaEditorScope]

# in the popup, pressing Esc:

KEYS >>> Listener.handleEvent(type = Traverse, stateMask = 0x0, keyCode = 0x1b,
character = 0x1b)
KEYS >>> Listener.handleEvent(type = Traverse, stateMask = 0x0, keyCode = 0x1b,
character = 0x1b)
CONTEXTS >>> [org.eclipse.ui.contexts.dialogAndWindow,
org.eclipse.jdt.ui.javaEditorScope, org.eclipse.ui.contexts.window]

# from now on: no trace whatsoever
Comment 13 Billy Biggs CLA 2004-06-21 12:29:17 EDT
Here is what we think is going wrong.

Shell.fixShellFocus() is trying to work around a GTK+ bug by sending a fake
FocusOut event to try and clear some GTK+ state.  However, if the control that
receives the FocusOut event does not have focus already, GDK will send a
FocusOut event up to the application.  This event then clears the hasFocus flag
on Shell and causes the behaviour you see.
Comment 14 Michael Van Meekeren CLA 2004-06-22 11:26:36 EDT
This is something we should investigate/fix for 3.0, as it really causes 
disruption in workflow.
Comment 15 Felipe Heidrich CLA 2004-06-23 17:23:00 EDT
We released a fix for this. Fixed > 20040623.

This is really a bug in GTK and if this fix is not enough, we are going to
remove the whole Shell.fixShellFocus() code.
Comment 16 Billy Biggs CLA 2004-06-24 09:59:55 EDT
I can still reproduce this in I200406240800 but not in HEAD.  I assume it didn't
yet make it into the builds.
Comment 17 Douglas Pollock CLA 2004-06-24 11:05:41 EDT
This fix is broken in at least 3 ways: 
1.) It has the potential to create a race condition with focus follows mouse.  
Moving the mouse around the screen, it is possible for Eclipse to steal focus 
after the mouse has left the window. 
 
2.) "Alt+Tab" to another window in KDE.  A pop-up appears while switching -- 
telling you which window you will switch to.  Releasing "Alt" while another 
window is selected, brings that window to top.  However, Eclipse will not 
repaint the section dirtied by the pop-up. 
 
3.) Taking a screenshot and switching desktops caused the following.  This is 
likely because of a race condition in which the input focus is being set on a 
window that is no longer mapped. 
 
The program '<unknown>' received an X Window System error. 
This probably reflects a bug in the program. 
The error was 'BadMatch (invalid parameter attributes)'. 
  (Details: serial 183493 error_code 8 request_code 42 minor_code 0) 
  (Note to programmers: normally, X errors are reported asynchronously; 
   that is, you will receive the error a while after causing it. 
   To debug your program, run it with the --sync command line 
   option to change this behavior. You can then get a meaningful 
   backtrace from your debugger if you break on the gdk_x_error() function.) 
 
Comment 18 Felipe Heidrich CLA 2004-06-24 14:20:04 EDT
Fixed again (SSQ). Billy and Doug, can you guys verify the new fix in HEAD ? 
Thanks
Comment 19 Billy Biggs CLA 2004-06-24 15:59:19 EDT
After using Eclipse from HEAD for a while under KDE 3.1 on RH9, I was able to
reproduce the caret-disappears problem from bug 58642.
Comment 20 Billy Biggs CLA 2004-06-24 16:14:28 EDT
I have reproducable steps for a persistent editor drop-down using the code from
HEAD.  KDE 3.1, RH9, Mist theme, Gtk+ 2.2.1.

1. Enter the Debug perspective.
2. Click on the contents of the variables view.
2. Click the editor drop-down.
3. Click back on the variables view, this closes the drop-down.
4. Click the editor drop-down again.  It is now persistent and won't go away.
Comment 21 Billy Biggs CLA 2004-06-24 16:20:39 EDT
Sorry, those steps are unreliable.  These steps are awesome.

1. Debug perspective.
2. Click on the outline view's tree view.
3. Click on the editor drop down.
4. Click on the variables view.

You're now in the bad state.  I will attach a screenshot of my setup.
Comment 22 Billy Biggs CLA 2004-06-24 16:21:51 EDT
Created attachment 12804 [details]
My setup
Comment 23 Billy Biggs CLA 2004-06-24 16:30:06 EDT
(Doug speaking:) From this bad state, just by fiddling around I was able to
descend into a place from which there is no return.  Eclipse will not shutdown
properly (needs to be hard killed), the editor drop-down is open and can't be
closed, and there is no focus control.