Recent

Author Topic: [SOLVED] Improvement of TQtWidgetSet.EnumDisplayMonitors functions  (Read 1850 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
The LCL has the following functions:
Code: Pascal  [Select][+][-]
  1. function TQtWidgetSet.EnumDisplayMonitors(hdc: HDC; lprcClip: PRect;
  2.   lpfnEnum: MonitorEnumProc; dwData: LPARAM): LongBool;
  3. var
  4.   i: integer;
  5.   Desktop: QDesktopWidgetH;
  6. begin
  7.   Desktop := QApplication_desktop();
  8.   Result := True;
  9.   for i := 0 to QDesktopWidget_numScreens(Desktop) - 1 do
  10.   begin
  11.     Result := Result and lpfnEnum(i + 1, 0, nil, dwData);
  12.     if not Result then break;
  13.   end;
  14. end;
Code: Pascal  [Select][+][-]
  1. function TQtWidgetSet.EnumDisplayMonitors(hdc: HDC; lprcClip: PRect;
  2.   lpfnEnum: MonitorEnumProc; dwData: LPARAM): LongBool;
  3. var
  4.   i: integer;
  5.   Desktop: QScreenH;
  6.   AArray: TPtrIntArray;
  7. begin
  8.   Desktop := QGuiApplication_primaryScreen();
  9.   Result := True;
  10.   QScreen_virtualSiblings(Desktop, @AArray);
  11.   for i := 0 to length(AArray) - 1 do
  12.   begin
  13.     Result := Result and lpfnEnum(i + 1, 0, nil, dwData);
  14.     if not Result then break;
  15.   end;
  16. end;


1/2 The lines
Code: Pascal  [Select][+][-]
  1. Result := Result and lpfnEnum(i + 1, 0, nil, dwData);
can be replaced with
Code: Pascal  [Select][+][-]
  1. Result := lpfnEnum(i + 1, 0, nil, dwData);

2/2 After that, the loops
Code: Pascal  [Select][+][-]
  1. for i := 0 to WHATEVER - 1 do
  2.   begin
  3.     Result := lpfnEnum(i + 1, 0, nil, dwData);
  4.     if not Result then break;
  5.   end;
can be replaced with
Code: Pascal  [Select][+][-]
  1. for i := 1 to WHATEVER do
  2.   begin
  3.     Result := lpfnEnum(i, 0, nil, dwData);
  4.     if not Result then break;
  5.   end;
 
Have a look at the following patch:
Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/interfaces/qt5/qtwinapi.inc b/lcl/interfaces/qt5/qtwinapi.inc
  2. index 23b452f16a..67b47c210e 100644
  3. --- a/lcl/interfaces/qt5/qtwinapi.inc
  4. +++ b/lcl/interfaces/qt5/qtwinapi.inc
  5. @@ -1553,9 +1553,9 @@ var
  6.  begin
  7.    Desktop := QApplication_desktop();
  8.    Result := True;
  9. -  for i := 0 to QDesktopWidget_numScreens(Desktop) - 1 do
  10. +  for i := 1 to QDesktopWidget_numScreens(Desktop) do
  11.    begin
  12. -    Result := Result and lpfnEnum(i + 1, 0, nil, dwData);
  13. +    Result := lpfnEnum(i, 0, nil, dwData);
  14.      if not Result then break;
  15.    end;
  16.  end;
  17. diff --git a/lcl/interfaces/qt6/qtwinapi.inc b/lcl/interfaces/qt6/qtwinapi.inc
  18. index 4424b1cdd7..9e3de22d21 100644
  19. --- a/lcl/interfaces/qt6/qtwinapi.inc
  20. +++ b/lcl/interfaces/qt6/qtwinapi.inc
  21. @@ -1557,9 +1557,9 @@ begin
  22.    Desktop := QGuiApplication_primaryScreen();
  23.    Result := True;
  24.    QScreen_virtualSiblings(Desktop, @AArray);
  25. -  for i := 0 to length(AArray) - 1 do
  26. +  for i := 1 to length(AArray) do
  27.    begin
  28. -    Result := Result and lpfnEnum(i + 1, 0, nil, dwData);
  29. +    Result := lpfnEnum(i, 0, nil, dwData);
  30.      if not Result then break;
  31.    end;
  32.  end;
« Last Edit: July 13, 2023, 11:16:00 am by lagprogramming »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4565
  • I like bugs.
Re: Improvement of TQtWidgetSet.EnumDisplayMonitors functions
« Reply #1 on: July 13, 2023, 11:09:15 am »
Actually it was a good cleanup and optimization. I applied it in be92e362e8.
Thanks.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
Re: Improvement of TQtWidgetSet.EnumDisplayMonitors functions
« Reply #2 on: July 15, 2023, 10:35:12 am »
Actually it was a good cleanup and optimization. I applied it in be92e362e8.
Thanks.

Ups. I forgot to include the third occurrence of the function. Here it is. After applying this patch all occurrences of the function(in all three qt, qt5 and qt6 directories) will look alike.
Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/interfaces/qt/qtwinapi.inc b/lcl/interfaces/qt/qtwinapi.inc
  2. index 531ece8772..98bdd246cb 100644
  3. --- a/lcl/interfaces/qt/qtwinapi.inc
  4. +++ b/lcl/interfaces/qt/qtwinapi.inc
  5. @@ -1590,9 +1590,9 @@ var
  6.  begin
  7.    Desktop := QApplication_desktop();
  8.    Result := True;
  9. -  for i := 0 to QDesktopWidget_numScreens(Desktop) - 1 do
  10. +  for i := 1 to QDesktopWidget_numScreens(Desktop) do
  11.    begin
  12. -    Result := Result and lpfnEnum(i + 1, 0, nil, dwData);
  13. +    Result := lpfnEnum(i, 0, nil, dwData);
  14.      if not Result then break;
  15.    end;
  16.  end;

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4565
  • I like bugs.
Re: [SOLVED] Improvement of TQtWidgetSet.EnumDisplayMonitors functions
« Reply #3 on: July 15, 2023, 12:09:58 pm »
Applied.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018