Reputation: 1
How is it possible in Lazarus(linux) to get a window handle knowing the PID of a third-party process in Linux. Perhaps an analogue of the function for Windows enumthreadwindows
I looked at the lclintf.pas module, there are some functions from Winapi. But there is no getting a list of HWND windows, running processes
Upvotes: -2
Views: 107
Reputation: 1249
There is a wmctrl
tool. You must install it. By running this command you can get list of window ids with their process ids. But I think it is for X only and may be don't work in Wayland.
wmctrl -l -p
You can use it in your FreePascal programs:
uses
Unix;
var
f: Text;
line: string;
begin
POpen(f, 'wmctrl -l -p', 'r');
while not eof(f) do
begin
ReadLn(f, line);
{ You can parse the line and get pid, wid, ... }
{ You can ignore windows do not belong to your desired pid }
end;
{ Close f after you done }
end.
You can use xdotool search --pid YOUR_PID
to get window ids of a process and use it like above in your pascal program.
But I think it is better to ask window manager about open windows. There are specs like Inter-Client Communication Conventions Manual
(ICCCM) and Extended Window Manager Hints. Long time ago I used libwnck
for a similar purpose. It is a C library, so you must provide pascal bindings for the functions you need.
Tools like xwininfo
and ... exists. Even you can use dbus to query window manager about open windows.
There must be methods in xlib, and maybe supported by lazarus. It needs deeper dive.
Upvotes: 1
Reputation: 169
I could go wrong but you may need to use xlib, x and Gtk2Proc
there is a small example in this post on Ubuntu 14 from Feb 2015
Upvotes: 0