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

Bug 404946

Summary: [GTK] display.getActiveShell() does not return active shell
Product: [Eclipse Project] Platform Reporter: Anatoly Spektor <spektor.anatoly>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: ericwill, gautier.desaintmartinlacaze, xixiyan
Version: 4.3   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Bug Depends on:    
Bug Blocks: 340067    

Description Anatoly Spektor CLA 2013-04-04 16:16:28 EDT
To reproduce this error here is the snippet:

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;


public class ShellTest {
	
	public static void main (String [] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.open();
		System.out.println(display.getActiveShell() == shell);
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}
Comment 1 Eric Williams CLA 2016-12-20 11:27:02 EST
I can reproduce this issue.
Comment 2 Xi Yan CLA 2018-08-24 10:49:09 EDT
This is not a bug, the snippet is calling display.getActiveShell before shell is active, so it will always be null. Changing it to something like 

shell.addMouseMoveListener(e -> {
		System.out.println(display.getActiveShell() == shell);
	});

gives the correct result.