Tuesday, November 2, 2021

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

Issue

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?


Solution

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.



Answered By - Socowi