Overload get(0, 'MonitorPositions')

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 Kommentare

Andrew Newell
Andrew Newell am 24 Mär. 2011
Do you have dual monitors?
Daniel Shub
Daniel Shub am 24 Mär. 2011
Yes, I have dual monitors.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Daniel Shub
Daniel Shub am 21 Sep. 2011

0 Stimmen

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 Kommentare

Jan
Jan am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (4)

Andrew Newell
Andrew Newell am 24 Mär. 2011

1 Stimme

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 Kommentare

Daniel Shub
Daniel Shub am 24 Mär. 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 am 24 Mär. 2011
I wonder how you can tell in advance what is "official"?

Melden Sie sich an, um zu kommentieren.

Matt Fig
Matt Fig am 24 Mär. 2011

1 Stimme

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 Kommentare

Daniel Shub
Daniel Shub am 24 Mär. 2011
I have edited the question in response to this...
I can do a number of things to accurately get the monitor positions. What I do not want to do is go through the code and change all the get(0,'MontorPositions') to some other function and hence the desire to overload something.
Matt Fig
Matt Fig am 24 Mär. 2011
Of course it is easy with Ctrl+f do replace all in about 1 second. My suggestion is more of a do-or-die idea. I do not think you can overload the root. Generally, messing with the root is a no-no.
Matt Fig
Matt Fig am 24 Mär. 2011
The other, non code-replacing option would be to simply unplug one of your monitors when using this toolbox.
Daniel Shub
Daniel Shub am 24 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Andrew Newell
Andrew Newell am 24 Mär. 2011

1 Stimme

2 Kommentare

Daniel Shub
Daniel Shub am 24 Mär. 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 am 24 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Andrew Newell
Andrew Newell am 24 Mär. 2011

1 Stimme

The underlying code is Java. You could try looking in the Undocumented Matlab site.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by