Comments on: Working with non-standard DPI displays https://undocumentedmatlab.com/blog_old/working-with-non-standard-dpi-displays Charting Matlab's unsupported hidden underbelly Thu, 07 Sep 2023 16:43:44 +0000 hourly 1 https://wordpress.org/?v=4.4.1 By: Yaroslavhttps://undocumentedmatlab.com/blog_old/working-with-non-standard-dpi-displays#comment-394702 Tue, 29 Nov 2016 19:28:44 +0000 https://undocumentedmatlab.com/?p=6736#comment-394702 Hi @Marco,

Thank you for your comment. Unfortunately, your solution tells me only how many monitors I can have. What I need is to know how many monitors I currently have.

To be more precise, MonitorPositions tells me how many monitors I had at the time of Matlab’s startup. It does not change if I attach a monitor after startup. This is the behaviour in my Windows 8.1 laptop.

I can do a little trick to circumvent this problem. By using the PointerLocation, I can check on which monitor the pointer is. For example

% get root handle
hRoot = groot;
% check if (a) there are at least two monitors
%          (b) pointer's x location is larger than 2nd monitor's x0 position
if     size(hRoot.MonitorPositions,1) >= 2 ...
    && hRoot.PointerLocation(1) > hRoot.MonitorPositions(2,1)
    % put figure on the second monitor
else
    % put figure on the first monitor
end

However, as you can see, it assumes you have control over the cursor’s position during execution. I wish there was an option to tell how many active monitors are there.

]]>
By: marcohttps://undocumentedmatlab.com/blog_old/working-with-non-standard-dpi-displays#comment-394677 Tue, 29 Nov 2016 14:12:53 +0000 https://undocumentedmatlab.com/?p=6736#comment-394677 Hi,
maybe this can be helpful:

>> monitorPos = get(0,'MonitorPositions')
monitorPos =
           1           1        1600         900
        1601           1        3200         900

then you can play with ‘pixels’ positions

]]>
By: Yaroslavhttps://undocumentedmatlab.com/blog_old/working-with-non-standard-dpi-displays#comment-394553 Mon, 28 Nov 2016 08:59:12 +0000 https://undocumentedmatlab.com/?p=6736#comment-394553 Hi Yair,

Suppose I have two monitors. How can I tell a figure to appear on the secondary one, if it exists? I can do something like

hFig = figure('Units','normalized','Position',[1.10 0.10 0.80 0.70]);

but it doesn’t tell me whether the second screen exists or not (if not, it will effectively hide the figure).

Best regards

]]>
By: Matthias Kirchhoffhttps://undocumentedmatlab.com/blog_old/working-with-non-standard-dpi-displays#comment-394173 Thu, 24 Nov 2016 14:09:11 +0000 https://undocumentedmatlab.com/?p=6736#comment-394173 As for me the solution using java.awt.Toolkit.getDefaultToolkit.getScreenSize does not work correctly when using more than one monitor.
Better use:

ge = javaObjectEDT(java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment());
gs = ge.getScreenDevices();
jmonitorposition = [];
if ~isempty(gs)
  for iRun_ = 1:size(gs,1)
     dm = gs(iRun_).getDisplayMode();
     jmonitorposition(iRun_,:) = [1 1 dm.getWidth dm.getHeight];
  end
end

Best regards
Matthias

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/working-with-non-standard-dpi-displays#comment-393560 Thu, 17 Nov 2016 12:47:37 +0000 https://undocumentedmatlab.com/?p=6736#comment-393560 @Thomas – the problem with your .NET solution is that it only works on Windows; the Java-based solution in my post works on all Matlab platforms, including Mac and Linux.

]]>
By: Thomas Pieperhttps://undocumentedmatlab.com/blog_old/working-with-non-standard-dpi-displays#comment-393555 Thu, 17 Nov 2016 12:17:13 +0000 https://undocumentedmatlab.com/?p=6736#comment-393555 If you feel more as a Microsoft family member you might want to use .NET commands. Try

NET.addAssembly('System.Windows.Forms');
System.Windows.Forms.Screen.PrimaryScreen.Bounds

or

System.Windows.Forms.SystemInformation.PrimaryMonitorSize

and you get something like

ans = 
 
  System.Drawing.Rectangle
  Package: System.Drawing
 
  Properties:
    Location: [1x1 System.Drawing.Point]
        Size: [1x1 System.Drawing.Size]
           X: 0
           Y: 0
       Width: 1920
      Height: 1080
        Left: 0
         Top: 0
       Right: 1920
      Bottom: 1080
     IsEmpty: 0
       Empty: [1x1 System.Drawing.Rectangle]

Greetings,

Thomas

]]>