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.
Last modified: 02/05/2006 (most likely earlier as a site migration in 2006 reset some dates) Tags: xprop
转载地址:http://mindspill.net/computing/linux-notes/get-window-name-using-xprop/
How to get window properties and information
Use the xprop
command to get a list of properties for the selected window, such as its name and state, and xwininfo
to get information about the window, such as its size and position. Run the command and click a window. You’ll get output a little like this:
steph@bpc ~ $ xprop
_NET_WM_ICON_GEOMETRY(CARDINAL) = 805, 1050, 200, 30
_NET_FRAME_EXTENTS(CARDINAL) = 1, 1, 22, 4
_NET_WM_ALLOWED_ACTIONS(ATOM) = _NET_WM_ACTION_CLOSE, _NET_WM_ACTION_ABOVE, _NET_WM_ACTION_BELOW, _NET_WM_ACTION_FULLSCREEN, _NET_WM_ACTION_MOVE, _NET_WM_ACTION_RESIZE, _NET_WM_ACTION_MAXIMIZE_HORZ, _NET_WM_ACTION_MAXIMIZE_VERT, _NET_WM_ACTION_SHADE, _NET_WM_ACTION_MINIMIZE, _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_STICK
WM_STATE(WM_STATE):
window state: Normal
icon window: 0x237cda0
_NET_WM_DESKTOP(CARDINAL) = 0
_NET_WM_STATE(ATOM) =
WM_HINTS(WM_HINTS):
Client accepts input or input focus: True
Initial state is Normal State.
bitmap id # to use for icon: 0x2a0006b
bitmap id # of mask for icon: 0x2a0006c
window id # of group leader: 0x2a00001
WM_WINDOW_ROLE(STRING) = "browser"
XdndAware(ATOM) = BITMAP
_MOTIF_DRAG_RECEIVER_INFO(_MOTIF_DRAG_RECEIVER_INFO) = 0x6c, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0
_NET_WM_ICON(CARDINAL) = Icon (16 x 16):
░ ░▒▒▒▒░
▒▒░▒▒▒ ░▒▒▒
░▒░▒▒░▒ ░░▒░▒
░░░░░░▒▒▓░░▒░░▒
▒░░░░░▒▒▓░░▒░ ░░
▒░░░░░░▒░░░▒▒ ░░
▒░░░░░░▒░▒▒▒▒ ░▒
▒░░▒▒▒▒▓▒▒▒▒▒ ░▒
▒░░░▒▒▓▒▒▒▒▒▒ ░▒
░▒░░▒▒▒▒▒▒▓▓░░░░
▒▒░░▒▒▒▒▓▒░░░▒░
▒▒░░░░▒▒▒▒░░▒▒
▒▒░░░░░░░░░▒
▒▒▒▒▒▒▒▒▒▒░
▒▒▒▒▒▒▒▒░
░░▒▒░░
Icon (32 x 32):
░▒▒▒▓▒▒▒░
▒▒▒░ ░▒▒▒
░▓▒░ ░▒▒░
░ ▒▓▒░ ▒▒▒▒░
▒▒░▒▓▒▒░░░░ ░▒▒░▒░
▓▒▒▓▒▒▒▒▒▓░ ░░░▒▒ ▒▒
▓▒░░░░░▒▒▒░ ░░░░▒░░░ ▒▒
░▒░░░░░▒▒▓▒ ░░░░▓░ ░▒░
▒▒░▒▒▒▒▒▒▒▒░░░ ░░░▒▒ ░░▒
░▒░▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░▒▒▓░ ▒
▒▒░▒▒▒▒▒▒▒▒░ ░▒░░░░░░░▒▒▓▒ ▒░
▒▒▒▒▒▒▒▒▒▒░░▒▒▒░░░░▒▒▒▒▒▒▒░ ▒▒
▓░▒▒▒▒▒▒▒░░░▒░░░░▒▒▒▒▒▒▓░▒░ ▒▓
▓░▒▒▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▓▒ ▒▓
▓░▒▒▒▒▒▒▓▓▓▓▒▒▒▒▒▒▒▒▓▓▓▓▒ ▒▓
░▓▒▒▒▒▒▒▓▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▒ ░ ░▒▓
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▒ ░ ░░▒
▒▒▒▒▒▒▒▒▒▒░░▒▒▒░░ ░▓▓▓▓▒░ ░░░░▒
░▒▒▒▒▒▒▒▒▒▒░░░░░▒▒▒▓▓▓▓░░░░░░▒░
▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓░░░░░░▒
▒▓▒▒▒▒▒▒░░▒▓▓▓▓▓▓▓▓▓▓▒░░░░░▒▒
░▓▓▓▒▒▒▒░░░▒▓▓▓▓▓▓▓▓▒░░░░░▒▓░
▒▓▓▓▒▒▒▒░░░░▒▓▓▓▓▒░░░░░▒▒▓▒
▓▓▓▒▒▒▒▒▒░░░░░░░░░░░░░░░▒░
░▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒░
▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒
▒▓▓▓▓▒▒▒▒▒▒▒░░░░░▒▒▒▒
░▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒░
░▒▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒░░
░░▒▒▒▓▓▓▓▓▓▒▒▒▒░░
░░▒▒▒▒▒▒▒▒▒░░
Icon (48 x 48):
░▒▒▓▓▓▓▓▒▒░
░▒▓▓▒░░ ░░▒▓▒░
▒▓▓▒ ▒▓▓▒
░▓▓▒░ ░░▒▓░
▒▓▓▒░ ░░ ░▓▒
░░ ░▓▓▓▒▒░░ ░▒ ▒▓░
▒░ ░▓▓▓▒▒░░░░░░ ░░▒░ ░▒▒
░░░░▓▓▓▓▒▒▒░▒▒▒░ ░░░▒▒░ ▒▒
▒░▒▒▒▓▒▒▒▒▒▒▒▒░ ░░▒░░▒ ▒▒
▒▒▒▒░░░░░░▒▒▒▒░ ░░░░░▒▒░ ░ ▒░
▒▒▒░░▒▒▒░▒▒▒▒▒░ ░░░░░░▒▒ ░▒
▒░░░▒▒▒▒▒▒▒▒▒▒░ ░░░░░░▒▒ ▒░
▒░▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░ ░░░░▒▓░ ░ ░
░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ░░░░░░▒▒▒ ░
░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░░░░░░░░░░▒▒▒▒▓
░▒▒▒▒▒▒▒▒▒▒▒▒▒▒░ ░▒░░░░░░░░░░▒▒▒▒▓░
░░▒▒▒▒▒▒▒▒▒▒▒▒░░ ▒▒▒░░░░░▒▒▒░░▒▒▒▒▓░ ░
░░▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒░░░░░░░▒▒▒▒▒▒▒▓▒▒▒░░ ░░
░░▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒░░░░░░▒▒▒▒▒▒▒▒▒▓▒ ▒ ░░ ░▒░
░▒▒▒▒▒▒▒▒▒▒░░░░░░▒░░░░░░▒▒▒▒▒▒▒▒▒▒▓▒ ░░ ░▒▒
░▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓ ░ ░▓▒
░▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓ ░▓▒
▒▒▒▒▒▒▒▒▒▒▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓ ░ ▒▒░
░▒▒▒▒▒▒▒▒▒▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓░ ░ ░▒░░
░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓░ ░░ ░░░░░
░▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▒▒▒▒▒▒░░░░▒▒▓▓▓▓▓▓▒▒░ ░░░░░░
▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒░░░░░ ▒▒▓▓▓▓▓▒░░ ░░░░░░
░▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░▒▒▒░▒▓▓▓▓▓▓░░░ ░░░░░░░
░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▒▒▒▒▒▓▓▓▓▓▓▓▓▓░░░░░░░░░▒
▒▒▓▒▒▒▒▒▒▒▒▒▒▒▓▓▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░▒░
░▒▓▒▒▒▒▒▒▒▒▒▒░▒▒▓▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░▒░
▒▓▓▒▒▒▒▒▒▒░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░▒▒░
▒▒▓▓▓▒▒▒▒▒▒░░░░░▒▒▓▓▓▓▓▓▓▓▓▓▒▒░░░░░░░░░▒▒
▒▓▓▓▒▒▒▒▒▒▒░░░░░░▒▓▓▓▓▓▓▓▒░░░░░░░░░░░▒▓░
▒▓▓▓▓▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▒░░░░░░░░░░░▒▒▒░
▒▓▓▓▓▒▒▒▒▒▒▒▒▒░░░░░░░░░░▒▒░░░░░░░▒▒░░
░▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░░░░░░░░
░▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░
░▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░
░▒▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░
░▒▒▓▓▓▓▒▒▒▒▒▒▒▒▒░░░░░░░░░▒▒▒▒
░░▒▒▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░
░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒▒▒▒░░
░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░▒▒▒░░
░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░
░░░░▒▒▒▒▒▒▒▒▒▒░░░░░
░░░░░░░░░░░
_NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 44040298
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL
_NET_WM_USER_TIME_WINDOW(WINDOW): window id # 0x2a00069
WM_CLIENT_LEADER(WINDOW): window id # 0x2a00001
_NET_WM_PID(CARDINAL) = 2835
WM_LOCALE_NAME(STRING) = "en_GB.UTF-8"
WM_CLIENT_MACHINE(STRING) = "bpc"
WM_NORMAL_HINTS(WM_SIZE_HINTS):
program specified minimum size: 0 by 0
window gravity: NorthWest
WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING, _NET_WM_SYNC_REQUEST
WM_CLASS(STRING) = "Navigator", "Firefox"
WM_ICON_NAME(STRING) = "Welcome to mindspill.net | mindspill.net - Mozilla Firefox"
_NET_WM_ICON_NAME(UTF8_STRING) = "Welcome to mindspill.net | mindspill.net - Mozilla Firefox"
WM_NAME(STRING) = "Welcome to mindspill.net | mindspill.net - Mozilla Firefox"
_NET_WM_NAME(UTF8_STRING) = "Welcome to mindspill.net | mindspill.net - Mozilla Firefox"
steph@bpc ~ $ xwininfo
xwininfo: Please select the window about which you
would like information by clicking the
mouse in that window.
xwininfo: Window id: 0x2a00068 "Welcome to mindspill.net | mindspill.net - Mozilla Firefox"
Absolute upper-left X: 645
Absolute upper-left Y: 22
Relative upper-left X: 1
Relative upper-left Y: 22
Width: 1274
Height: 1023
Depth: 24
Visual: 0x21
Visual Class: TrueColor
Border width: 0
Class: InputOutput
Colormap: 0x20 (installed)
Bit Gravity State: NorthWestGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no
Map State: IsViewable
Override Redirect State: no
Corners: +645+22 -1921+22 -1921-35 +645-35
-geometry 1274x1023+644+0
These details can be used with programs like devilspie to apply window rules for resizing, positioning, etc of windows.
转载地址:http://mindspill.net/computing/linux-notes/get-window-properties-and-information/