| Summary: | [Widgets] GTK: shellActivated event only sent when display loop is spun | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Markus Keller <markus.kell.r> |
| Component: | SWT | Assignee: | Platform-SWT-Inbox <platform-swt-inbox> |
| Status: | CLOSED DUPLICATE | QA Contact: | |
| Severity: | minor | ||
| Priority: | P3 | CC: | daniel_megert, ericwill, pinnamur, Silenio_Quarti, xixiyan |
| Version: | 3.6 | Keywords: | triaged |
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Linux-GTK | ||
| Whiteboard: | |||
I can still reproduce this issue with the snippet attached. *** This bug has been marked as a duplicate of bug 469525 *** |
HEAD Run the snippet below on GTK and on WinXP. When the window is open, click into your workbench window. Wait for 10 seconds (the window activates itself), then click the close box of the window. Sequence on WinXP: Sequence on GTK: ------------------ ---------------- shellActivated() shellActivated() shellDeactivated() shellDeactivated() forcing active forcing active shellActivated() +---- shell is active: true | shell is active: true forced active | forced active +-> shellActivated() => On GTK, the shellActivated event is only sent out long after the shell became active (when the display loop is run the next time). Workaround is to manually run the display loop. If you e.g. add long start = System.currentTimeMillis(); while (start + 2000 > System.currentTimeMillis()) { while (display.readAndDispatch()) ; } after shell.forceActive();, then the sequence becomes like the one on Windows. This burned us in an automated test that failed as soon as the target workbench lost focus. I've worked around the problem for now. package org.eclipse.swt.snippets; import org.eclipse.swt.events.*; import org.eclipse.swt.widgets.*; public class ShellActivate { public static void main(String[] args) { final Display display= new Display(); final Shell shell= new Shell(display); shell.addShellListener(new ShellAdapter() { public void shellDeactivated(ShellEvent e) { System.out.println("shellDeactivated()"); display.timerExec(2000, new Runnable() { public void run() { System.out.println("forcing active"); shell.forceActive(); System.out.println("shell is active: " + (display.getActiveShell() == shell)); System.out.println("forced active"); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } }); } public void shellActivated(ShellEvent e) { System.out.println("shellActivated()"); } }); shell.setSize(160, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }