Recent

Author Topic: Screen.Monitors[x] Returns incorrect Left properties  (Read 5663 times)

Tony Stone

  • Full Member
  • ***
  • Posts: 216
Screen.Monitors[x] Returns incorrect Left properties
« on: November 27, 2021, 01:14:30 am »
It is hard for me to explain so i created a couple screen shots and a demo project.  But I need to basically draw my multi monitor display on a form.  The problem is some of the monitors are returning the wrong left values.  I am showing my real monitor layout and what my program is calculating.


It seems to only return improper left values for the top row of monitors.

I am trying to write an application to help setup xrandr so I can ultimately use this to call commands to xrandr

Tony Stone

  • Full Member
  • ***
  • Posts: 216
Re: Screen.Monitors[x] Returns incorrect Left properties
« Reply #1 on: November 27, 2021, 02:30:25 am »
So part of my code was completely wrong.  So the demo project is probably useless.... however.... i still l cannot seem to get the proper Left value for the upper monitors.

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Screen.Monitors[x] Returns incorrect Left properties
« Reply #2 on: November 27, 2021, 02:49:05 am »
I don't have a setup near me with multiple monitors so it's hard for me to decide however, I am sure you are not on windows and this leads me to believe that maybe there is a widget issue that could be reporting bad info.

  Have you determined if the returned info is correct from the monitor's array ?

  Also, if that is correct then maybe it could be a form issue but that could still be a widget issue, too.
The only true wisdom is knowing you know nothing

Tony Stone

  • Full Member
  • ***
  • Posts: 216
Re: Screen.Monitors[x] Returns incorrect Left properties
« Reply #3 on: November 27, 2021, 02:53:28 am »
I don't have a setup near me with multiple monitors so it's hard for me to decide however, I am sure you are not on windows and this leads me to believe that maybe there is a widget issue that could be reporting bad info.

  Have you determined if the returned info is correct from the monitor's array ?

  Also, if that is correct then maybe it could be a form issue but that could still be a widget issue, too.

Well... I am still slowly working things out.  I found that rebooting my computer I am NOW getting proper info back from the array of monitors.  It may have been due to changing monitor settings through the Linux Mint Display Manager.  So to that end, no I am not on windows.

So what I am struggling with now is  getting my displays(tpanels are used to represent a display) to scale down and fit in the main panel...  like my screen shots show.  Mathematically I know how to scale it down but I am running into issues with division.  I am close to working it out though.  Will report back soon.
 :-[
« Last Edit: November 27, 2021, 03:54:23 am by Tony Stone »

Tony Stone

  • Full Member
  • ***
  • Posts: 216
Re: Screen.Monitors[x] Returns incorrect Left properties
« Reply #4 on: November 27, 2021, 04:15:29 am »
HOLY CRAP!!!!!  This works and it took me so long to figure out.  >:(   :-[

I wonder if anyone sees any initial major issues with it?  My god this little bit of code just caused me a lot of frustration.  It shouldn't have been this hard!  DAM IT. lol   I have such a hard time working things out of my brain into actual code some times.  I was much smarter as a kid.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormResize(Sender: TObject);
  2. var
  3.   i, highR: integer;
  4. begin
  5.  
  6.   highR := 0;
  7.   for i := 0 to screen.MonitorCount - 1 do
  8.   begin
  9.     if Screen.Monitors[i].BoundsRect.Right > highR then
  10.       highR := Screen.Monitors[i].WorkareaRect.Right;
  11.     Writeln('Highest Right: ' + IntToStr(highR));
  12.  
  13.   end;
  14.  
  15.   scaleLObyXY := pnlLayout.Width / int64(highR);
  16.   scaleTocntrX := pnlLayout.Width div 4;
  17.   scaleTocntrY:=pnlLayout.Height div 4;
  18.  
  19.   for i := 0 to Screen.MonitorCount - 1 do
  20.   begin
  21.  
  22.     schDisplays[i].Left := (trunc(Screen.Monitors[i].Left * scaleLObyXY) div
  23.       2) + scaleTocntrX;
  24.     schDisplays[i].Top := (trunc(Screen.Monitors[i].Top * scaleLObyXY) div 2) + scaleTocntrY;
  25.  
  26.     schDisplays[i].Width := (trunc(Screen.Monitors[i].Width * scaleLObyXY) div 2);
  27.     schDisplays[i].Height := (trunc(Screen.Monitors[i].Height * scaleLObyXY) div 2);
  28.   end;
  29.  
  30. end;      
  31.  

Tony Stone

  • Full Member
  • ***
  • Posts: 216
Re: Screen.Monitors[x] Returns incorrect Left properties
« Reply #5 on: November 27, 2021, 04:32:08 pm »
I don't have a setup near me with multiple monitors so it's hard for me to decide however, I am sure you are not on windows and this leads me to believe that maybe there is a widget issue that could be reporting bad info.

  Have you determined if the returned info is correct from the monitor's array ?

  Also, if that is correct then maybe it could be a form issue but that could still be a widget issue, too.

So all wise one, Jamie!  I think I have my monitor information resolved(for now).  Problem is if I change the display positions through Cinnamon display manager I can no longer get accurate info.  But lets skip that for now.

Right now I have it creating panels to represent each display.  I have it working nicely where the user can rearrange them however they like.  So my next challenge is this:

I need any overlapping edges to snap to the closest panel edge of other panels in their arrangement.  So i started "coding" and so far have not had any success.  It looks like I am gonna end up with a total mess of boolean and arrays of edges and all sorts of crazyness i started.  Making these things snap to the edge of the closest shouldn't be so complicated?  You have any tips on how you would approach this?  Or you know of any simple demos out there that do something similar?

My first attempt ended up with about 7 levels of loops and about 20 booleans and i ended up deleting 150 lines last night. lol!  Was a total disaster! 

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: Screen.Monitors[x] Returns incorrect Left properties
« Reply #6 on: November 27, 2021, 08:30:10 pm »
Not sure for other OS, but on Windows Monitors can have negative coordinates. (I have that on my setup)

So you should also get the lowest Left.



Tony Stone

  • Full Member
  • ***
  • Posts: 216
Re: Screen.Monitors[x] Returns incorrect Left properties
« Reply #7 on: November 27, 2021, 08:37:45 pm »
Not sure for other OS, but on Windows Monitors can have negative coordinates. (I have that on my setup)

So you should also get the lowest Left.

Ok that is a valid point.  Maybe Linux will do the same in some envronments?  I will look into it.  But this is gonna end up being a Linux only application.  Unless there is an xRandR type thing for Windows as well?

So I think you have a valid point... It is noted.  In the meantime I am still struggling with allowing my user to move the panels and have them snap to edges.  The amount of code I have written and erased in the past 10 hours for this is pathetic!  %) lol

I now understand why the existing Layout Configuration tool of Linux Mint is so damd buggy!  Actually... even Windows XP back in the day had a buggy layout tool.  The logic put together in my brain seems flawless... but once i start putting into code its a disaster.  One attempt had about 7 loops deep.

Out of curiosity, is there a potential limit on how many loops could be inside of another loop?  Like a theoretical depth?

 

TinyPortal © 2005-2018