Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Getting / Setting Monitor for SWT Application?
Getting / Setting Monitor for SWT Application? [message #440188] Mon, 26 July 2004 12:49 Go to next message
Benjamin Pasero is currently offline Benjamin PaseroFriend
Messages: 337
Registered: July 2009
Senior Member
Hi,

in the case an SWT application is used on a Dual-Monitor computer, is it
possible to GET the monitor the application is currently displayed? I
would use that information to save it in settings and SET the monitor for
the application after next startup again.

Any getter for current used monitor and setter where to display the
application available?

Thanks for helping,
Ben
Re: Getting / Setting Monitor for SWT Application? [message #440189 is a reply to message #440188] Mon, 26 July 2004 13:36 Go to previous messageGo to next message
Brian Sam-Bodden is currently offline Brian Sam-BoddenFriend
Messages: 8
Registered: July 2009
Junior Member
Benjamin,
Maybe this would work. If you get the list of monitors for a display
with display.getMonitors() then loop throught that list and check if you
shell's bounds intersect the monitor's bounds

Rectangle r = myShell.getBounds();
for (int i = 0; i < monitors.length; i++) {
if (monitors[i].getBounds().intersects(r)) {
myMonitor = monitors[i];
}
}


Benjamin Pasero wrote:

> Hi,
>
> in the case an SWT application is used on a Dual-Monitor computer, is it
> possible to GET the monitor the application is currently displayed? I
> would use that information to save it in settings and SET the monitor for
> the application after next startup again.
>
> Any getter for current used monitor and setter where to display the
> application available?
>
> Thanks for helping,
> Ben
>
Re: Getting / Setting Monitor for SWT Application? [message #440216 is a reply to message #440189] Mon, 26 July 2004 17:00 Go to previous messageGo to next message
Benjamin Pasero is currently offline Benjamin PaseroFriend
Messages: 337
Registered: July 2009
Senior Member
Hi Brian,

thanks for this way to get out on which Monitor the SWT App is running.
But one big problem is still, that SWT does not seem to provide any method
like "setMonitor". I just looked through Display and Shell widget. I am
going to open a feature request on this item.

Ben

> Benjamin,
> Maybe this would work. If you get the list of monitors for a display
> with display.getMonitors() then loop throught that list and check if you
> shell's bounds intersect the monitor's bounds

> Rectangle r = myShell.getBounds();
> for (int i = 0; i < monitors.length; i++) {
> if (monitors[i].getBounds().intersects(r)) {
> myMonitor = monitors[i];
> }
> }


> Benjamin Pasero wrote:

> > Hi,
> >
> > in the case an SWT application is used on a Dual-Monitor computer, is it
> > possible to GET the monitor the application is currently displayed? I
> > would use that information to save it in settings and SET the monitor for
> > the application after next startup again.
> >
> > Any getter for current used monitor and setter where to display the
> > application available?
> >
> > Thanks for helping,
> > Ben
> >
Re: Getting / Setting Monitor for SWT Application? [message #440219 is a reply to message #440216] Mon, 26 July 2004 17:35 Go to previous messageGo to next message
Brion Vibber is currently offline Brion VibberFriend
Messages: 21
Registered: July 2009
Junior Member
Benjamin Pasero wrote:
> thanks for this way to get out on which Monitor the SWT App is running.
> But one big problem is still, that SWT does not seem to provide any method
> like "setMonitor". I just looked through Display and Shell widget. I am
> going to open a feature request on this item.

What do you need that Shell.setLocation() doesn't do?

-- brion vibber (brion @ pobox.com)
Re: Getting / Setting Monitor for SWT Application? [message #440221 is a reply to message #440219] Mon, 26 July 2004 18:21 Go to previous messageGo to next message
Benjamin Pasero is currently offline Benjamin PaseroFriend
Messages: 337
Registered: July 2009
Senior Member
Brion Vibber wrote:

> Benjamin Pasero wrote:
> > thanks for this way to get out on which Monitor the SWT App is running.
> > But one big problem is still, that SWT does not seem to provide any method
> > like "setMonitor". I just looked through Display and Shell widget. I am
> > going to open a feature request on this item.

> What do you need that Shell.setLocation() doesn't do?

Hm, but how is the location calculated when two monitors are used? Will
the max location be the two monitor's sizes added?

And there is a situation where setLocation() does not seem to work. A user
maximized the shell on the second monitor, closed the application and
restarted it. The Shell was then placed maximized on the first monitor
(although I am saving the location on exit and resetting it on startup).
Maybe that is only working with non maximized Shells.

> -- brion vibber (brion @ pobox.com)
Re: Getting / Setting Monitor for SWT Application? [message #440223 is a reply to message #440221] Mon, 26 July 2004 19:37 Go to previous messageGo to next message
Brion Vibber is currently offline Brion VibberFriend
Messages: 21
Registered: July 2009
Junior Member
Benjamin Pasero wrote:
> Brion Vibber wrote:
>>Benjamin Pasero wrote:
>>>thanks for this way to get out on which Monitor the SWT App is running.
>>>But one big problem is still, that SWT does not seem to provide any method
>>>like "setMonitor". I just looked through Display and Shell widget. I am
>>>going to open a feature request on this item.
>
>>What do you need that Shell.setLocation() doesn't do?
>
> Hm, but how is the location calculated when two monitors are used? Will
> the max location be the two monitor's sizes added?

Normally there is a global coordinate space; each monitor occupies some
portion of that space. See the other posting which gave an example of
using Monitor.getBounds(), this should let you know where each monitor
is located in the coordinate space and how big it is.

As an example; if I have my PowerBook connected to an external monitor,
and have the internal screen also active, my screens will be laid out
something like this:

+------+
+----+ 1 |
| 2 | |
+----+------+

monitor 1: position (0,0) size 1280x1024
monitor 2: position (-1024, 256) size 1024x768

So if I left a window at (-800, 400) size 500x350, I'll save those
coordinates and restore it at (-800, 400) with size 500x350. I'd be
really surprised if that doesn't work.

You should also check that there is actually a monitor covering that
space, though: laptops in particular may frequently change monitor
configuration, and a window that's created offscreen can be hard to work
with.

> And there is a situation where setLocation() does not seem to work. A user
> maximized the shell on the second monitor, closed the application and
> restarted it. The Shell was then placed maximized on the first monitor
> (although I am saving the location on exit and resetting it on startup).
> Maybe that is only working with non maximized Shells.

Maximizing can do funny things, particularly on Windows. Usually you
can't change the position of a maximized window... also maximized
windows on Windows have coordinates which extend a few pixels off the
screen, which may confuse things when you then maximize it. Are you
setting the position first, then maximizing, or the other way around?

-- brion vibber (brion @ pobox.com)
Re: Getting / Setting Monitor for SWT Application? [message #440225 is a reply to message #440223] Mon, 26 July 2004 20:13 Go to previous message
Benjamin Pasero is currently offline Benjamin PaseroFriend
Messages: 337
Registered: July 2009
Senior Member
Thanks for this detailed explanation. I must admit, that the problem with
a Shell being maximized is not a real problem ^^. I was simply not storing
the location of the Shell in the settings file, because on a
single-monitor its pretty useless, whereas on a dual-monitor the Shell may
be maximized on the second Monitor and the location is not (0, 0).
Tomorrow I am going to play around with it, connecting a second Monitor to
my notebook. Using setLocation should do it.

Ben

> Benjamin Pasero wrote:
> > Brion Vibber wrote:
> >>Benjamin Pasero wrote:
> >>>thanks for this way to get out on which Monitor the SWT App is running.
> >>>But one big problem is still, that SWT does not seem to provide any method
> >>>like "setMonitor". I just looked through Display and Shell widget. I am
> >>>going to open a feature request on this item.
> >
> >>What do you need that Shell.setLocation() doesn't do?
> >
> > Hm, but how is the location calculated when two monitors are used? Will
> > the max location be the two monitor's sizes added?

> Normally there is a global coordinate space; each monitor occupies some
> portion of that space. See the other posting which gave an example of
> using Monitor.getBounds(), this should let you know where each monitor
> is located in the coordinate space and how big it is.

> As an example; if I have my PowerBook connected to an external monitor,
> and have the internal screen also active, my screens will be laid out
> something like this:

> +------+
> +----+ 1 |
> | 2 | |
> +----+------+

> monitor 1: position (0,0) size 1280x1024
> monitor 2: position (-1024, 256) size 1024x768

> So if I left a window at (-800, 400) size 500x350, I'll save those
> coordinates and restore it at (-800, 400) with size 500x350. I'd be
> really surprised if that doesn't work.

> You should also check that there is actually a monitor covering that
> space, though: laptops in particular may frequently change monitor
> configuration, and a window that's created offscreen can be hard to work
> with.

> > And there is a situation where setLocation() does not seem to work. A user
> > maximized the shell on the second monitor, closed the application and
> > restarted it. The Shell was then placed maximized on the first monitor
> > (although I am saving the location on exit and resetting it on startup).
> > Maybe that is only working with non maximized Shells.

> Maximizing can do funny things, particularly on Windows. Usually you
> can't change the position of a maximized window... also maximized
> windows on Windows have coordinates which extend a few pixels off the
> screen, which may confuse things when you then maximize it. Are you
> setting the position first, then maximizing, or the other way around?

> -- brion vibber (brion @ pobox.com)
Previous Topic:Where are tasks data stored?
Next Topic:Anyone get SWT to work in Eclipse 3.0 on OSX?
Goto Forum:
  


Current Time: Tue Apr 23 13:06:09 GMT 2024

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

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

Back to the top