In X, if you run the xprop command and click on a window, it will print verbose details about the selected window. You can pipe this through a text processing program like awk to pick out particular details, such as the window name.
xprop |awk '/WM_CLASS/{print $4}'
In this example, if $4 doesn't work, try $3.