Overload get(0, 'MonitorPositions')

18 views (last 30 days)
Daniel Shub
Daniel Shub on 24 Mar 2011
I am using someone else's toolbox that calls get(0, 'MonitorPositions') all over the place. The problem is that on my system get(0, 'MonitorPositions') returns nonsense. I understand that dual monitors are not officially supported by MATLAB despite the existence of a property like MonitorPositions.
Is it possible to overload either get(0, 'MonitorPositions') or whatever is called by get(0, 'MonitorPositions')?
The problem is not getting the monitor positions from the OS. I can write a MATLAB function that uses either java or system calls to get the monitor positions. I do not want to edit the code in the toolbox.
  2 Comments
Andrew Newell
Andrew Newell on 24 Mar 2011
Do you have dual monitors?
Daniel Shub
Daniel Shub on 24 Mar 2011
Yes, I have dual monitors.

Sign in to comment.

Accepted Answer

Daniel Shub
Daniel Shub on 21 Sep 2011
While it is not a very satisfying answer, upgrading to r2011a fixed my problem. I am not sure if this is a universal solution or not, but it makes me happy.
  2 Comments
Jan
Jan on 21 Sep 2011
I haven't seen this thread before.
You can overload the "get" command by creating a function with this name in the Matlab path:
function Out = get(varargin)
Then you can check if the first two inputs are {0, 'MonitorPositions'} and create an adjusted output. In all other cases you can forward the input to the built-in "get":
Out = builtin('get', varargin{:});
You have to catch missing output and multiple inputs, but it is possible with some effort.
However, if upgrading solves the known bug, this is a far better idea.
Daniel Shub
Daniel Shub on 21 Sep 2011
You are right about just overloading get. It seemed like overkill to overwrite a crucial function just to intercept one property of one handle. I was worried about performance and multiple inputs and in general screwing something up. What I really wanted to do was intercept whatever the hell was called to actually get the monitor position.

Sign in to comment.

More Answers (4)

Andrew Newell
Andrew Newell on 24 Mar 2011
Judging by the documentation for Root properties, MATLAB does officially support dual monitors, but this is a documented bug. You could try doing this:
set(0,'MonitorPositions',get(0,'ScreenSize'))
but there's no guarantee you'll get good results.
  2 Comments
Daniel Shub
Daniel Shub on 24 Mar 2011
>> set(0, 'MonitorPositions', [1,1,1024,1280])
??? Error using ==> set
Attempt to modify a property that is read-only.
Object Name : root
Property Name : 'MonitorPositions'.
As for official support, it really is a mixed message. There is documentation and even reported bugs. My support request asking if there was something I could change in my software or hardware configuration to get the correct values was meet with "MATLAB is not officially tested on multi-monitor setups, and so this is not an officially supported setup." They also tried to be helpful and provided some java code that correctly gets my monitor positions.
Andrew Newell
Andrew Newell on 24 Mar 2011
I wonder how you can tell in advance what is "official"?

Sign in to comment.


Matt Fig
Matt Fig on 24 Mar 2011
What does the code you are using do with the value returned by
get(0,'MontorPosition')
Depending on your answer to that question, you could just hardcode some the pixel width and height of one of your monitors in the code. For example, everywhere you see this code, replace it with:
[1 1 1920 1200]
Or with whatever monitor size you have.
  4 Comments
Matt Fig
Matt Fig on 24 Mar 2011
The other, non code-replacing option would be to simply unplug one of your monitors when using this toolbox.
Daniel Shub
Daniel Shub on 24 Mar 2011
Yes, but it is not my code. Ideally, I will get the change accepted into the repo so that I do not have to keep editing the code on every update. I agree that messing with the root is not ideal. I was really hoping that there was an underlying function that was being called that I could change.

Sign in to comment.


Andrew Newell
Andrew Newell on 24 Mar 2011
  2 Comments
Daniel Shub
Daniel Shub on 24 Mar 2011
Yes, the toolbox is using the information to set the position and size of multiple figures. Since the toolbox is using the information to set the position of the figures, the default value will not being used.
Andrew Newell
Andrew Newell on 24 Mar 2011
One solution, then, is to not set the position and size of the figures. Just let the figures open wherever Matlab decides to open them.

Sign in to comment.


Andrew Newell
Andrew Newell on 24 Mar 2011
The underlying code is Java. You could try looking in the Undocumented Matlab site.

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!