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

Bug 365097

Summary: shell gets deactivated without reason and also with no deactivation event
Product: [Eclipse Project] Platform Reporter: Andrei Diaconu <andi_dm1>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 3.7.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description Andrei Diaconu CLA 2011-11-29 11:41:37 EST
In the snippet below, just click anywhere inside the shell.

The shell will deactivate itself and no event will be generated. After this, the shell is in a strange state: you need to click twice on content area to activate it. Even clicking on the close button has no effect (first click).

In the console you will see that the shell is activated twice, without being first deactivated.

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;

public class IncorrectDeactivateWithNoEvent {

	public static void main(String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display);
		shell.addListener(SWT.MouseUp, new Listener() {
			@Override
			public void handleEvent(Event event) {
				final Shell invisibleShell = new Shell();
				invisibleShell.setLayout(new FillLayout());
				final Composite composite = new Composite(invisibleShell, SWT.NONE);
				final Image image = new Image(display, 1, 1);
				final GC gc = new GC(image);
				composite.print(gc);
				gc.dispose();
				invisibleShell.dispose();
				image.dispose();
				shell.removeListener(SWT.MouseUp, this);
			}
		});
		final Listener listener = new Listener() {
			@Override
			public void handleEvent(Event event) {
				switch (event.type) {
					case SWT.Activate:
						System.out.println("activated");
						break;
					case SWT.Deactivate:
						System.out.println("deactivated");
						break;
				}
			}
		};
		shell.addListener(SWT.Activate, listener);
		shell.addListener(SWT.Deactivate, listener);
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
}
Comment 1 Andrei Diaconu CLA 2011-11-30 04:01:44 EST
To workaround the problem, and get the shell active again, call setActive() twice. Users will notice the titlebar flickering, though.
Comment 2 Lars Vogel CLA 2019-11-14 03:15:31 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

If the bug is still relevant, please remove the "stalebug" whiteboard tag.