Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » getActiveShell() on linux-gtk
getActiveShell() on linux-gtk [message #458157] Mon, 11 July 2005 01:55 Go to next message
Eclipse UserFriend
Hello,

I'm having a problem with some code that works fine on the windows version
of my rcp app but is failing on the linux-gtk version. I'm wondering if
it's a bug or if I'm doing something wrong. Here's the code.

System.out.println("shell: " + Display.getDefault().getActiveShell());
FileDialog dialog = new FileDialog
(Display.getDefault().getActiveShell(), SWT.SAVE);
String fileName = dialog.open();
System.out.println("shell: " +
Display.getDefault().getActiveShell());
MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(),
SWT.ICON_INFORMATION);

On windows, getActiveShell() returns the shell before and after the
FileDialog is opened. On linux, getActiveShell() returns the shell
before, but returns null after. Therefor my MessageBox throws an
exception.

Any ideas? Thanks.

Chris
Re: getActiveShell() on linux-gtk [message #458170 is a reply to message #458157] Mon, 11 July 2005 10:54 Go to previous messageGo to next message
Eclipse UserFriend
Chris F wrote:
> On windows, getActiveShell() returns the shell before and after the
> FileDialog is opened. On linux, getActiveShell() returns the shell
> before, but returns null after. Therefor my MessageBox throws an
> exception.

Spin the event loop.

Basically, for a shell to become active on Linux GTK+, a request is sent to
the window manager. When the window manager sees the request, it might (or
might not) mark that shell as active. For this communication to take
place, the event loop must be making progress.

Note that in some case, the dialog may never become active. For example,
two simultaneous requests to make different shells active may result in
only one shell actually becoming active.



cheers,
d.
Re: getActiveShell() on linux-gtk [message #458171 is a reply to message #458157] Mon, 11 July 2005 11:04 Go to previous messageGo to next message
Eclipse UserFriend
> I'm having a problem with some code that works fine on the windows
> version of my rcp app but is failing on the linux-gtk version. I'm
> wondering if it's a bug or if I'm doing something wrong. Here's the code.
>
> [...]
>
> On windows, getActiveShell() returns the shell before and after the
> FileDialog is opened. On linux, getActiveShell() returns the shell
> before, but returns null after. Therefor my MessageBox throws an
> exception.

getActiveShell() returns null if another application has focus, which
means that using it is always a bit of a race since the user could have
used Alt-Tab to go somewhere else before your code runs. Under Linux,
focus management is done by the window manager, so often in SWT we must
wait until we get the event from the WM before knowing which shell is
active.

I would suggest modifying the code to handle getActiveShell()
returning null. However, if you're seeing some weirdness with respect
to handling FileDialog shells, please file a bug. :)

-Billy
Re: getActiveShell() on linux-gtk [message #458239 is a reply to message #458171] Mon, 11 July 2005 13:20 Go to previous messageGo to next message
Eclipse UserFriend
> I would suggest modifying the code to handle getActiveShell()
> returning null. However, if you're seeing some weirdness with respect
> to handling FileDialog shells, please file a bug. :)

Would you suggest that I store a reference to the Shell after the first
getActiveShell() call and pass it to the MessageBox? Or is there another
preferred way to do this instead of doing MessageBox mb = new
MessageBox(Display.getDefault().getActiveShell(), ...);

Thanks,
Chris
Re: getActiveShell() on linux-gtk [message #458242 is a reply to message #458239] Mon, 11 July 2005 14:07 Go to previous message
Eclipse UserFriend
Chris F wrote:
>> I would suggest modifying the code to handle getActiveShell()
>> returning null. However, if you're seeing some weirdness with respect
>> to handling FileDialog shells, please file a bug. :)
>
> Would you suggest that I store a reference to the Shell after the first
> getActiveShell() call and pass it to the MessageBox? Or is there
> another preferred way to do this instead of doing MessageBox mb = new
> MessageBox(Display.getDefault().getActiveShell(), ...);

Since MessageBox creates a modal dialog, you should explicitly pass
in the Shell for which it will be modal for. Using getActiveShell()
seems strange to me since, if you have multiple windows, you'll just end
up with whichever one happens to have focus at the time :) Presumably
this dialog is because of an interaction with one of your application's
windows, no?

-Billy
Previous Topic:Launch shortcut not showing up
Next Topic:Table size in Form
Goto Forum:
  


Current Time: Tue Nov 04 03:19:08 EST 2025

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

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

Back to the top