Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Strange shell behaviour when switching workspace(The Shell is moving to its original location when switching workspace)
Strange shell behaviour when switching workspace [message #1693959] Wed, 29 April 2015 13:47 Go to next message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
Hi,

Here is a little snippet showing the problem I have:
1- Run the program,
2- Click on the "open shell" button,
3- A shell opens, change its position using "drag and drop" process,
4- Switch to another workspace,
5- Come back to previous workspace (where the shell is open)

=> The shell has moved to its original opening location.
How can I prevent this from happening ?

Note that this does not happen if the updateCounter() method is not called...
(FYI, I use Debian and the last version of swt for Linux 64-bit).

package shell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class Main {

	private Display display;
	private Shell mainShell;
	private Label label;
	private int i = 0;
	private final static int MAX_I = 10;
	
	private void run() {
		display = new Display();
		mainShell = new Shell(display);
		mainShell.setLayout(new FillLayout());
		final Button button = new Button(mainShell, SWT.PUSH);
		button.setText("Open shell");
		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				openShell();
			}
		});
		mainShell.pack();
		mainShell.open();
		while (!mainShell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}

	public static void main(String[] args) {
		new Main().run();
	}


	private void openShell() {
		final Shell childShell = new Shell(mainShell, SWT.NO_TRIM | SWT.ON_TOP); 
		childShell.setLayout(new GridLayout());
		
		Composite composite = new Composite(childShell, SWT.NONE);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		composite.setLayout(new GridLayout(2, false));

		Label prefix = new Label(composite, SWT.NONE);
		prefix.setText("Count is:");
		prefix.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, true, true));

		label = new Label(composite, SWT.NONE);
		label.setText(i+"");
		label.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, true, true));
		childShell.setSize(150, 150);
		childShell.setLocation(200, 200);
		
		// Add ability to move shell around
		MoveListener moveListener = new MoveListener(childShell);
		composite.addListener(SWT.MouseDown, moveListener);
		composite.addListener(SWT.MouseUp, moveListener);
		composite.addListener(SWT.MouseMove, moveListener);

		childShell.open();


		display.timerExec(100, new Runnable() {
			public void run() {
				if( !childShell.isDisposed()) {
					updateCounter();
					display.timerExec(100, this);
				}
			}
		});
	}
	
	
	private void updateCounter() {
		if (i < MAX_I) {
			i = i + 1;
		} else {
			i = 0;
		}
		label.setText(i+"");
	}


	public class MoveListener implements Listener {

	    private Shell shell;
	    private Point origin;
	    
	    public MoveListener(Shell shell) {
	    	this.shell = shell;
	    }
	    
	    public void handleEvent(Event event) {
	        switch (event.type) {
	        case SWT.MouseDown:
	            origin = new Point(event.x, event.y);
	            break;
	        case SWT.MouseUp:
	            origin = null;
	            break;
	        case SWT.MouseMove:
	            if (origin != null) {
	                Point p = shell.getDisplay().map(shell, null, event.x, event.y);
	        		shell.setLocation(p.x - origin.x, p.y - origin.y);
	            }
	            break;
	        }
	    }
	}


Thanks in advance for your help,
Helene.
Re: Strange shell behaviour when switching workspace [message #1694274 is a reply to message #1693959] Mon, 04 May 2015 07:07 Go to previous messageGo to next message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
Hi again,

Did anyone manage to reproduce this bug ?



Re: Strange shell behaviour when switching workspace [message #1695801 is a reply to message #1694274] Tue, 19 May 2015 12:00 Go to previous message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
Hi again,

We implemented nearly the same snippet in C++ using GTK (versions 2 and 3) and we do not have the same problem, So we think that the problem is due to SWT.

Here is the code (file Test.cpp) :

#include <gtk/gtk.h>
#include <sstream>
#include <iostream>

GtkWidget *popup_window;

static void on_popup_clicked(GtkButton*, GtkWidget*);

static gpointer thread_func(gpointer data) {
	int x = 0;
	while (true) {
		std::stringstream os;
		os << "value " << x;

		usleep(10000);

		gdk_threads_enter();
		gtk_label_set_text(GTK_LABEL(data), os.str().c_str());
		gdk_threads_leave();

		if (x == 100) {
			gtk_window_move(GTK_WINDOW(popup_window), 500, 200);
		}
		x++;
	}

	return NULL;
}

int main(int argc, char *argv[]) {
	GtkWidget *window, *button, *vbox;
	GError *error = NULL;

	gdk_threads_init();

	gtk_init(&argc, &argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(window), "Parent window");
	gtk_container_set_border_width(GTK_CONTAINER(window), 10);
	gtk_widget_set_size_request(window, 100, 50);
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

	button = gtk_button_new_with_label("Pop Up");
	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_popup_clicked), (gpointer) window);

	vbox = gtk_vbox_new(FALSE, 3);
	gtk_box_pack_end(GTK_BOX(vbox), button, FALSE, FALSE, 5);
	gtk_container_add(GTK_CONTAINER(window), vbox);

	gtk_widget_show_all(window);
	gtk_main();

	return 0;
}

void on_popup_clicked(GtkButton* button, GtkWidget* pWindow) {
	GError *error = NULL;

	popup_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(popup_window), "Pop Up window");
	gtk_container_set_border_width(GTK_CONTAINER(popup_window), 10);
	gtk_window_set_resizable(GTK_WINDOW(popup_window), FALSE);

	gtk_window_set_decorated(GTK_WINDOW(popup_window), FALSE);
	gtk_window_move(GTK_WINDOW(popup_window), 0, 200);

	GtkWidget * label = gtk_label_new("This is a Normal label");
	GtkWidget *vbox = gtk_vbox_new(FALSE, 3);
	gtk_box_pack_end(GTK_BOX(vbox), label, FALSE, FALSE, 5);
	gtk_container_add(GTK_CONTAINER(popup_window), vbox);

	GThread *thread = g_thread_create(thread_func, (gpointer) label, FALSE, &error);

	gtk_widget_show_all(popup_window);
	gtk_widget_grab_focus(popup_window);
}


To compile this class for GTK2, use :
gcc -Wall -g Test.cpp -o testgtk2 `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0 gthread-2.0` -lstdc++


To compile this class for GTK3, use :
gcc -Wall -g Test.cpp -o testgtk3 `pkg-config --cflags gtk+-3.0` `pkg-config --libs gtk+-3.0 gthread-2.0` -lstdc++


Anyone could help ?
Thanks !
Helene




Previous Topic:Column group in swt/jface Table
Next Topic:Aligning composites
Goto Forum:
  


Current Time: Tue Mar 19 07:23:18 GMT 2024

Powered by FUDForum. Page generated in 0.02373 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top