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

Bug 210915

Summary: Shell#getLocation() wrong after setVisible(false)
Product: [Eclipse Project] Platform Reporter: Markus Keller <markus.kell.r>
Component: SWTAssignee: Xi Yan <xixiyan>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ericwill, marlin.cremers, snorthov, xixiyan
Version: 3.4Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux-GTK   
See Also: https://git.eclipse.org/r/127513
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=eaeacca6acd37400d458d7d93f4638e912c2d3b6
Whiteboard:

Description Markus Keller CLA 2007-11-26 07:38:30 EST
I20071120-1300

Invisible shells report a wrong (old) location on Linux-GTK. Running the snippet below and clicking the "Show" button produces this output:

before setLocation:Point {-30000, 0}
after setLocation:Point {108, 168}
before setVisible(false): Point {108, 168}
after setVisible(false): Point {-30000, 0}
before setVisible(true): Point {-30000, 0}
after setVisible(true): Point {108, 168}

Expected: all but the first Point should be Point {108, 168}.
Works as expected on Windows.

------------------------------------------------

package org.eclipse.swt.snippets;

import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class WrongLoc {

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Main");
    shell.setLayout(new RowLayout());

    final Button button = new Button(shell, SWT.PUSH);
    button.setText("Show");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            showHover(shell, button);
        }
    });
    shell.setBounds(100, 100, 300, 200);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

static void showHover(final Shell shell, final Button button) {
    final Display display = shell.getDisplay();
    Rectangle bb = button.getBounds();
    final Point pos = button.toDisplay(bb.x, bb.y + bb.height + 5);

    final Shell hover = new Shell(shell, SWT.ON_TOP | SWT.NO_TRIM);
    hover.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
    hover.setBounds(-30000, 0, 100, 50);
    hover.setVisible(true);

    display.asyncExec(new Runnable() {
        public void run() {
            System.out.println("before setLocation:" + hover.getLocation());
            hover.setLocation(pos);
            System.out.println("after setLocation:" + hover.getLocation());
        }
    });

    display.timerExec(2000, new Runnable() {
        public void run() {
            Point loc = hover.getLocation();
            System.out.println("before setVisible(false): " + loc);
            hover.setVisible(false);
            Point loc2 = hover.getLocation();
            System.out.println("after setVisible(false): " + loc2);
        }
    });

    display.timerExec(4000, new Runnable() {
        public void run() {
            Point loc = hover.getLocation();
            System.out.println("before setVisible(true): " + loc);
            hover.setVisible(true);
            Point loc2 = hover.getLocation();
            System.out.println("after setVisible(true): " + loc2);
        }
    });
}
}
Comment 1 Markus Keller CLA 2007-11-27 03:41:13 EST
Not that severe any more for me, since I don't use this call sequence any more.
Comment 2 Marlin Cremers CLA 2012-10-12 15:29:39 EDT
Is there any chance this will be fixed?
Comment 3 Eric Williams CLA 2018-08-16 10:33:49 EDT
Xi, please investigate.
Comment 4 Eclipse Genie CLA 2018-08-16 10:53:54 EDT
New Gerrit change created: https://git.eclipse.org/r/127513
Comment 6 Eric Williams CLA 2018-08-16 14:29:17 EDT
(In reply to Eclipse Genie from comment #5)
> Gerrit change https://git.eclipse.org/r/127513 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=eaeacca6acd37400d458d7d93f4638e912c2d3b6

Patch is in master, thanks Xi.
Comment 7 Xi Yan CLA 2018-09-24 10:55:36 EDT
Verified in I20180923-1800.