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

3 次查看(过去 30 天)
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

回答(1 个)

Walter Roberson
Walter Roberson 2016-12-27
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 个评论
Leo Simon
Leo Simon 2016-12-27
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by