Preventing focus theft while running matlab from the command line and creating figures

2 views (last 30 days)
There have been several posts on this subject such as this thread , and proposed solutions such as the program sfigure, but nothing works for me. I'm running R2016b from linux, and opening matlab with the flags
-nosplash -nodesktop
When I run the following code, using @Walter Roberson's fix proposed in the first link
close all;
figure(1);
set(0,'CurrentFigure',1);
plot(1:10);
or using the program `sfigure` suggested in the second link
close all;
sfigure(1);
plot(1:10);
the focus thief remains as active as ever. I would so love to put this thief away for life.
Thanks for any suggestions

Answers (1)

Walter Roberson
Walter Roberson on 27 Dec 2016
Creating a figure always gives it focus. The discussion in the other thread is about how to reduce the other circumstances under which the focus might get stolen.
If you set the new figure Visible off and drawnow() almost immediately after you create the figure then you reduce the time during which the focus is at risk. The focus will mostly go back to where it was when you make the new figure visible off, but not necessarily completely reliably. You can reduce the window even more by creating it with visible off: the documentation implies that it would still be temporarily made the current figure in that case, but it can be difficult to tell the cases apart.
  1 Comment
Leo Simon
Leo Simon on 27 Dec 2016
Thanks Walter, I'm afraid I don't understand the suggestion. I tried the following command, which I thought might be what you were suggesting:
h = figure('Visible','off');drawnow(); plot(1:10); h.Visible='on';
but the focus was still lost. Is there some reason why matlab doesn't provide us with some way to prevent loss of focus? It's very hard for me to come up with some reason why this protocol should be hard-wired?

Sign in to comment.

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!