Recent

Author Topic: Track windows cross-platform  (Read 1995 times)

LemonParty

  • Sr. Member
  • ****
  • Posts: 439
Track windows cross-platform
« on: April 08, 2026, 06:03:55 pm »
Hello.

I want to know if there is a cross platform way (Windows, Linux and probably macOS) to track window position and size. I have a window handle and I want to know when this window changes position or resizes.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

dsiders

  • Hero Member
  • *****
  • Posts: 1596
Re: Track windows cross-platform
« Reply #1 on: April 08, 2026, 07:43:36 pm »
Hello.

I want to know if there is a cross platform way (Windows, Linux and probably macOS) to track window position and size. I have a window handle and I want to know when this window changes position or resizes.

OnResize and OnChangeBounds.

https://lazarus-ccr.sourceforge.io/docs/lcl/forms/tform.html

LemonParty

  • Sr. Member
  • ****
  • Posts: 439
Re: Track windows cross-platform
« Reply #2 on: April 08, 2026, 09:57:19 pm »
No, I mean track positions and sizes of windows of any applications, include not created by Lazarus.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

dsiders

  • Hero Member
  • *****
  • Posts: 1596
Re: Track windows cross-platform
« Reply #3 on: April 08, 2026, 10:32:42 pm »
No, I mean track positions and sizes of windows of any applications, include not created by Lazarus.

That is decidedly platform-specific... and in the case of QT not available at all (to my knowledge).

440bx

  • Hero Member
  • *****
  • Posts: 6382
Re: Track windows cross-platform
« Reply #4 on: April 08, 2026, 10:33:46 pm »
No, I mean track positions and sizes of windows of any applications, include not created by Lazarus.
before anything, I don't have a cross platform solution.

In Windows, it's not hard to do but, it could potentially be a CPU hog.  The solution is to enumerate the windows every "n" milliseconds and for every top level window get its window rectangle (not the client's.)  Compare that value (which is the current) with a value that was previously saved.  Anytime the window rectangle is different it means that either the position, the size or both changed.

The amount of CPU used will depend on how often you decide to enumerate the windows. if you enumerate no more often than every 20ms, the CPU usage should likely be acceptable.

HTH.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Xenno

  • Jr. Member
  • **
  • Posts: 87
    • BS Programs
Re: Track windows cross-platform
« Reply #5 on: April 09, 2026, 02:57:56 pm »
There is GetWindowRect function in LCLIntf, but it's said not working on non-Windows.
Lazarus 4.0, Windows 10, https://www.youtube.com/@bsprograms

PascalDragon

  • Hero Member
  • *****
  • Posts: 6381
  • Compiler Developer
Re: Track windows cross-platform
« Reply #6 on: April 10, 2026, 07:21:06 am »
I want to know if there is a cross platform way (Windows, Linux and probably macOS) to track window position and size. I have a window handle and I want to know when this window changes position or resizes.

On Linux with Wayland that is simply not possible as Wayland does not support such functionality by design (even for one's own windows!).

LemonParty

  • Sr. Member
  • ****
  • Posts: 439
Re: Track windows cross-platform
« Reply #7 on: April 10, 2026, 05:37:47 pm »
I want to know if there is a cross platform way (Windows, Linux and probably macOS) to track window position and size. I have a window handle and I want to know when this window changes position or resizes.

On Linux with Wayland that is simply not possible as Wayland does not support such functionality by design (even for one's own windows!).
Linux users advertise Linux as a home OS. But how anyone suppose to use it if basic things like check window position is not supported. Why developers of Wayland don't allow this?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

dsiders

  • Hero Member
  • *****
  • Posts: 1596
Re: Track windows cross-platform
« Reply #8 on: April 10, 2026, 07:43:43 pm »
I want to know if there is a cross platform way (Windows, Linux and probably macOS) to track window position and size. I have a window handle and I want to know when this window changes position or resizes.

On Linux with Wayland that is simply not possible as Wayland does not support such functionality by design (even for one's own windows!).
Linux users advertise Linux as a home OS. But how anyone suppose to use it if basic things like check window position is not supported. Why developers of Wayland don't allow this?

Linux doesn;t have one window manager, desktop, and API... it has many. And they're all different. So, Linux has "freedom of choice"'d itself into relative desktop obscurity. It has tools like wmctrl and xwininfo to do those things... but they're not integrated into QT or GTK for example. Because that would require them to support the mechanisms for every window manager.

Wayland is just a brain-dead specification. And by resisting such basic functionality they demonstrate why they are both arrogant and ignorant.

But at least Linux users don't have to endure advertisements in their start menu.

 

TinyPortal © 2005-2018