Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Preventing figure focus stealing in Linux

Subject: Preventing figure focus stealing in Linux

From: Christian Schultz

Date: 1 Dec, 2010 12:06:05

Message: 1 of 5

I'm doing several plot commands in a lengthy for loop, and I do not want to bring the plot windows to focus everytime I plot in them. I tried to download this m-file http://www.mathworks.com/matlabcentral/fileexchange/8919-smartsilent-figure but to no avail. I also tried set(0, 'CurrentFigure', figure_handle); before each plot, but this still brings the figure into focus. It's quite frustrating that I cannot use other programs while running my script because my figures keep stealing focus. How can I change this? I'm using Ubuntu 10.04

On a sidenote: Is it possible to specify somewhere in Matlab that I always want to launch the editor so it is visible in the lower panel that shows currently running programs? I find it annoying that this feature is not on by default.

Subject: Preventing figure focus stealing in Linux

From: Steven_Lord

Date: 1 Dec, 2010 14:58:09

Message: 2 of 5



"Christian Schultz" <spamcatcher@remove.this.easy.com> wrote in message
news:id5dnd$3a3$1@fred.mathworks.com...
> I'm doing several plot commands in a lengthy for loop, and I do not want
> to bring the plot windows to focus everytime I plot in them. I tried to
> download this m-file
> http://www.mathworks.com/matlabcentral/fileexchange/8919-smartsilent-figure
> but to no avail. I also tried set(0, 'CurrentFigure', figure_handle);
> before each plot, but this still brings the figure into focus. It's quite
> frustrating that I cannot use other programs while running my script
> because my figures keep stealing focus. How can I change this? I'm using
> Ubuntu 10.04

How are you plotting into your figures? Are you calling the FIGURE
function? If so, the behavior you're seeing is the documented and expected
behavior. See paragraphs 2 and 4 in the Description section of the function
reference page for FIGURE:

http://www.mathworks.com/help/techdoc/ref/figure.html

If you're calling FIGURE _and_ using the SET command, then it's not the SET
that's bringing the figure to the foreground but the FIGURE call.

One approach to consider, depending on what window manager you're using and
whether or not your application requires user interaction, is running MATLAB
on one desktop and running your other programs on another.

http://userbase.kde.org/Glossary#Virtual_Desktops

> On a sidenote: Is it possible to specify somewhere in Matlab that I always
> want to launch the editor so it is visible in the lower panel that shows
> currently running programs? I find it annoying that this feature is not on
> by default.

The answer to that is probably going to depend on what window manager you're
using.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Preventing figure focus stealing in Linux

From: Christian Schultz

Date: 2 Dec, 2010 10:06:04

Message: 3 of 5

Thank you for taking your time to answer this.

To elaborate: The structure of my script is as this

h1=figure(1)
h2=figure(2) ... etc

start of loop

set(0,'CurrentFigure',h1)
plot something

set(0,'CurrentFigure',h2)
plot something else

end of loop

I use the standard window manager in Ubuntu: Gnome.


"Steven_Lord" <slord@mathworks.com> wrote in message <id5nq1$6gv$1@fred.mathworks.com>...
>
>
> "Christian Schultz" <spamcatcher@remove.this.easy.com> wrote in message
> news:id5dnd$3a3$1@fred.mathworks.com...
> > I'm doing several plot commands in a lengthy for loop, and I do not want
> > to bring the plot windows to focus everytime I plot in them. I tried to
> > download this m-file
> > http://www.mathworks.com/matlabcentral/fileexchange/8919-smartsilent-figure
> > but to no avail. I also tried set(0, 'CurrentFigure', figure_handle);
> > before each plot, but this still brings the figure into focus. It's quite
> > frustrating that I cannot use other programs while running my script
> > because my figures keep stealing focus. How can I change this? I'm using
> > Ubuntu 10.04
>
> How are you plotting into your figures? Are you calling the FIGURE
> function? If so, the behavior you're seeing is the documented and expected
> behavior. See paragraphs 2 and 4 in the Description section of the function
> reference page for FIGURE:
>
> http://www.mathworks.com/help/techdoc/ref/figure.html
>
> If you're calling FIGURE _and_ using the SET command, then it's not the SET
> that's bringing the figure to the foreground but the FIGURE call.
>
> One approach to consider, depending on what window manager you're using and
> whether or not your application requires user interaction, is running MATLAB
> on one desktop and running your other programs on another.
>
> http://userbase.kde.org/Glossary#Virtual_Desktops
>
> > On a sidenote: Is it possible to specify somewhere in Matlab that I always
> > want to launch the editor so it is visible in the lower panel that shows
> > currently running programs? I find it annoying that this feature is not on
> > by default.
>
> The answer to that is probably going to depend on what window manager you're
> using.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: Preventing figure focus stealing in Linux

From: Steven_Lord

Date: 2 Dec, 2010 14:40:51

Message: 4 of 5



"Christian Schultz" <spamcatcher@remove.this.easy.com> wrote in message
news:id7r2c$3cj$1@fred.mathworks.com...
> Thank you for taking your time to answer this.
>
> To elaborate: The structure of my script is as this
>
> h1=figure(1)
> h2=figure(2) ... etc
>
> start of loop
>
> set(0,'CurrentFigure',h1)
> plot something

What function are you using to do this plotting? If you're using PLOT, as
an experiment try changing it to use LINE instead. The syntax is very
similar; you'll probably just need to modify the way the line specification
is handled.

> set(0,'CurrentFigure',h2)
> plot something else
>
> end of loop
>
> I use the standard window manager in Ubuntu: Gnome.

I don't use Gnome, so I don't know the answer to that part of your question.
You'll have to wait for someone who is more familiar with that window
manager or contact Technical Support.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Preventing figure focus stealing in Linux

From: Walter Roberson

Date: 2 Dec, 2010 16:37:49

Message: 5 of 5

On 02/12/10 4:06 AM, Christian Schultz wrote:
> Thank you for taking your time to answer this.

Hi, Chris -- did we work together in Winnipeg?

> To elaborate: The structure of my script is as this
>
> h1=figure(1)
> h2=figure(2) ... etc
>
> start of loop
>
> set(0,'CurrentFigure',h1)
> plot something
>
> set(0,'CurrentFigure',h2)
> plot something else
>
> end of loop

Create the figures once and hide them (set the 'Visible' property
'off'). After that, never set a figure as the current figure: instead
explicitly create axes with the figure specified as the Parent, and each
time you plot, specify the axes as the Parent. Many of the plotting
calls accept an axis as the first parameter instead of requiring you to
use a 'Parent' property/value pair.

Explicitly specifying which graph each graphics object is to go on is
safer programming: if you rely on "current axes" and the user clicks
something while the program is running, the "current axes" or "current
figure" can change when the program does not expect it to, leading to
graphics being applied to the wrong place. It is a nuisance to transform
longish code to this form the first time, but if your code is like mine,
in the process of doing so you will probably find places where the
assumptions of what the current graphic are incorrect. Writing new code
in the style of explicitly specifying every parent turns out to not take
much extra effort.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us