Thanks for your suggestions. Unfortunately, the issue seems to be more complex than expected, at least on the Mac.
@ASerge:
In macOS
Screen.DesktopWidth unfortunately delivers the same value as
Screen.Width.
@GetMem:
Your example generally works. On the Mac, however, (and probably with Windows, too), it is also possible to arrange monitors vertically. I have expanded your code in form of the following function, which checks for the arrangement of monitors and only adds their widths, if they are horizontally arranged:
function ExtendedScreenWidth: longint;
var
width, lastRight: longint;
i: integer;
begin
width := 0;
lastRight := -1;
for i := 0 to Screen.MonitorCount - 1 do
if Screen.Monitors[i].Left > lastRight then
begin
width := width + Screen.Monitors[i].Width;
lastRight := Screen.Monitors[i].Left;
end;
result := width;
end;
Now, having this solved with your help I have still another problem:
I wanted to know the width of the desktop area in order to be able to programmatically distribute the windows of my application over the total virtual screen area in a multi-monitor setup. Unfortunately, if I set the
left property of a window to a value right of the
width property of the first monitor (in order to place it on the second screen) this seems to be automatically corrected by the LCL (at least on macOS), so that the window is positioned on the first monitor again. To be more concrete, I have two monitors with a width of 1280 pixels each. This sums up to a total width of 2560 pixels. If I set the
left property of my window to e.g. 2000 pixels this is "corrected", so that it becomes 720. Of course it is possible to manually move the windows across the total desktop area.
Could this "automatic correction" be a bug, and how is it possible to circumvent it?