Community
Participate
Working Groups
Created attachment 243494 [details] NPE stack trace My environment: * Luna M7 ** EMF Compare nightly * Linux Mint 16 (with Mate Desktop) I'm working on EMF Compare project and at some point I have to get the active shell. To do so, I receive a SWT event (from the workbench) and I use event.display.getActiveShell(). However the activeShell is set to null. I have also tried with Display.getDefault().getActiveShell() but it is null too. If I force the use of GTK2 (export SWT_GTK3=0) this display has a correct activeShell (!=null). To reproduce: * Download EMF Compare sources (http://git.eclipse.org/c/emfcompare/org.eclipse.emf.compare.git) * Set the Luna target platform (available in org.eclipse.emf.compare-parent/targetPlatforms/luna-sdk.target) * Run a runtime platform * Compare the 3 models provided (see attachment). ** Select the three files (extlibraryLeft.ecore,extlibraryOrigin.ecore and extlibraryRight.ecore) ** Open the contextual menu (Compare With > Each Other) * Change the active group to default (http://www.eclipse.org/emf/compare/documentation/latest/user/user-guide.html#Grouping_Differences) You will get an NPE (see attachment). This NPE comes from a display with an activeShell set to null. This does not happen on neither on Mac or Windows neither with a GTK2 Linux.
Created attachment 243495 [details] Project to reproduce
*** Bug 435635 has been marked as a duplicate of this bug. ***
Hello Arthur. I doesn't look like it's guaranteed that there will be an active Shell (in focus) when this code is called. In fact, I've looked around the platform code and they pass around the IWorkbenchWindow which can be used to retrieve the Shell so I think that's the way to go. For example, see org.eclipse.ui.actions.ExportResourcesAction.ExportResourcesAction As for the difference between GTK2 and GTK3, I have noticed that in GTK3, there is a FOCUS_OUT_EVENT which calls gtk_focus_out_event and nulls out the activeShell. To me, it doesn't look like this is a bug, it means that when the context menu is brought up, it gets focus and the main Shell loses it. Perhaps some SWT expert can clarify.
Hello Mark, I agree that nothing tells us that the active shell should not be null. However I think eclipse is multi platform so I would have expected that the same code does the same way in GTK3 and in the other platforms (GTK2, Mac and Windows which are all the platform we have tested for the moment). I'm afraid that if this behavior stays the same in GTK3 a lot a of bugs will be raised in other projects too. If you are sure that this the expected behavior I would change this in my code however I'm not sure this is the correct solution. Thanks for your help, Regards, Arthur
This bug also breaks the 'Show In' context menu, see bug 436635.
Created attachment 243989 [details] MenuActiveShell.java - SWT Snippet Here's an SWT snippet that reproduces the problem on GTK3, where it prints "menuShown: activeShell == null". On GTK2 (env var. SWT_GTK3 = 0), it prints "menuShown: activeShell == Shell {snippet.MenuActiveShell}" The problem seems to be in Control#gtk_event_after(int, int) line 3134, where int /*LONG*/ grabHandle = OS.gtk_grab_get_current (); if (grabHandle != 0) { if (OS.G_OBJECT_TYPE (grabHandle) == OS.GTK_TYPE_MENU ()) { display.ignoreFocus = true; break; } } has "grabHandle == 0" on GTK3 and hence it misses to set display.ignoreFocus.
I have pushed a patch to gerrit - https://git.eclipse.org/r/#/c/28064/ The change is to not set activeShell to null in the Shell's FocusOut event handler when there is a context menu showing. I've tested with the snippet from comment 6 and with the context menus in Eclipse as well.
(In reply to Arun Thondapu from comment #7) > I have pushed a patch to gerrit - https://git.eclipse.org/r/#/c/28064/ +1 for RC4. The patch works fine for the scenarios without detached views, but we still get FocusOut/In and activation events on GTK3 when the context menu is shown. On GTK2 and Windows, no such events are sent. This needs to be investigated for 4.5. There are still problems with detached views on GTK, but I'll open a separate bug for that.
(In reply to Arun Thondapu from comment #7) > I have pushed a patch to gerrit - https://git.eclipse.org/r/#/c/28064/ Merged to master - http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=988bede29f39493a457063957c6a9c6fd48a2ddf
I verified this defect in I20140605-1635 We are still getting the FocusIn and FocusOut evets in GTK3. These are not coming in GTK2.
(In reply to Sravan Kumar Lakkimsetti from comment #10) > I verified this defect in I20140605-1635 > > We are still getting the FocusIn and FocusOut evets in GTK3. These are not > coming in GTK2. This probably causes bug 436749.
(In reply to Markus Keller from comment #8) > There are still problems with detached views on GTK, but I'll open a > separate bug for that. Bug 436749. (In reply to Dani Megert from comment #11) > This probably causes bug 436749. That's probably a different issue, see bug 436749 comment 2. Verified in I20140605-1635 and opened bug 436841 for comment 8.
I have verified with our workflow and everything is working just fine now. Thanks a lot.