How can I get the WID via bash which window the mouse pointer is over?

605 Views Asked by At

The question refers to: Linux Ubuntu, with Cinnamon desktop

Several program windows can be displayed on a desktop.

How can I get the WID via bash which window the mouse pointer is over?

1

There are 1 best solutions below

0
On BEST ANSWER

I cannot test this at the moment, but maybe xdotool offers a way to get the window under the mouse cursor. From man xdotool:

getmouselocation [--shell]
Outputs the x, y, screen, and window id of the mouse cursor.

I assume the mentioned window id belongs to the window under the mouse cursor. To retrieve it, use

declare "$(xdotool getmouselocation --shell | grep WINDOW)"
echo "$WINDOW"

The window id can then be used in other tools like xwininfo -id <wdid> to get more information.