I run a MATLAB script in workspace 1. This generates several plots. In the mean time I switch to workspace 2 and work there. My problem is that the plots are popping up in workspace 2.
Is it possible to lock the software on a specific workspace, so while MATLAB generates the plots in workspace 1, I can work in workspace 2 without the disruption of the popping up plots?
IMPORTANT EDIT
Below a rewritten version of the script from the first answer (below). The differences:
WM_CLASS
and the targeted workspace are now arguments to run the script. Only use either the first or the second (identifying) part of theWM_CLASS
(see further below: how to use)When the script starts, it shows a notification (example
gedit
):The script
How to use
The script needs both
wmctrl
andxdotool
:Copy the script above into an empty file, save it as
lock_towspace.py
Of your specific application, find out the
WM_CLASS
: open your application, run in a terminal:The output will look like (in your case):
Either use the first or the second part in the command to run the script.
The command to run the script then is:
In the command, the last section;
2,2
is the workspace where you want to lock the application to (without spaces: (!) column, row), in "human" format; the first column/row is1,1
OUTDATED ANSWER:
(second) TEST VERSION
The script below locks a specific application to its initial workspace. If the script is started, it determines on which workspace the application resides. All additional windows the application produces will be moved to the same workspace in a split second.
The focus issue is solved by automatically re- focussing on the window that was focussed before the additional window was produced.
The script
How to use
The script needs both
wmctrl
andxdotool
Copy the script into an empty file, save it as
keep_workspace.py
determine your application's `WM_CLASS' by opening the application, then open a terminal and run the command:
Then click on your application's window. Copy the output, looking like
"sun-awt-X11-XFramePeer", "MATLAB R2015a - academic use"
in your case, and place it between single quotes in the head section of the script, as indicated.Run the script with the command:
If it works as you like, I'll add a toggle function. Although it works already for a few hours on my system, bu it might need some tweaking first however.
Notes
Although you should not notice it, the script does add some processor load to the system. On my elderly system I noticed an increase of 3-10%. If you like how it works, I will probably further tweak it to reduce the load.
The script, as it is, assumes the secundary windows are of the same class as the main window, like you indicated in a comment. With a (very) simple change, the secondary windows can be of another class however.
Explanation
Although probably not very interesting for an average reader, the script works by calculating in vectors. On startup, the script calculates:
wmctrl -d
wmctrl -lG
From then on, the script looks for new windows of the same application, with the output of
xprop WM_CLASS
, looks up their position in the same way as above and moves them to the "original" workspace.Since the newly created window "stole" the focus from the last used window the user was working on, the focus is subsequently set to the window that had focus before.
The issue, I believe, was resolved years ago, but I can't refrain from being a bit ironic. Jacob's answer is extremely helpful and generous; the python script is super useful and I really appreciate his work on the answer. But within the question it is a complete overkill, because the easiest solution is to tell Matlab that you want to create the plot without actual drawing. This is done by setting the value figure object's property 'Visible' to 'off' when creating the figure with a plot in Matlab… For example:
The figures could be saved as images of the common type (i.e. jpeg). If saving is not needed, this Visible property could be set back to default
fig.Visible = 'on';
when the code runs to the end and the figure will appear. But in case when a bunch of pictures needs to be produced in a batch, this is the only way to use your computer while the code is running.