apt-file
apt-file 是一个软件包,它索引可用存储库中软件包的内容,并允许您在所有可用软件包中搜索特定文件。 例如,假设您下载一个软件尝试运行它时,收到一条消息,告诉您无法找到特定的库文件。您就可以使用 apt-file 快速找出包含特定库的软件包可以解决问题,满足该依赖关系。
apt-get install apt-file # 安装
apt-file update # 更新数据库
apt-file search <filename> # 可以查找包含指定文件的软件包
# example:
# apt-file search libmp3lame.so.0
# libmp3lame0: /usr/lib/x86_64-linux-gnu/libmp3lame.so.0
# 这告诉我们要满足文件libmp3lame.so.0的依赖关系,我们需要安装包libmp3lame0。您还会注意到,在结果中包名称的右侧,它告诉我们如果您安装该特定包,文件将被安装到哪里。在上面的示例中,通过安装软件包 libmp3lame0 ,我们搜索的文件“libmp3lame.so.0”的副本将安装到文件夹“/usr/lib/x86_64-linux-gnu/”中。
另一个方法
dpkg -S libmp3lame.so.0
libmp3lame0:amd64: /usr/lib/x86_64-linux-gnu/libmp3lame.so.0
# 展示了相同的基本信息。注意:apt-file适用于所有可用的软件包,无论是否安装。而dpkg -S仅查看已安装的软件包。
apt source {pkg}
apt source {pkg} # 可以用来下载指定包源码
# example
# apt source bash # 下载 bash 包源码(到当前目录)
以上如何帮助我们解决一个问题?
我们希望查找获取窗口状态的函数,通过手册我们找到了一个函数(
gdk_window_get_state
)但是使用上有问题,并非我们所熟知的最大化,最小化,全屏等状态,而是还重叠了聚焦,平铺等状态。 而我们记得xwininfo
工具函数是有打印过 窗口状态的。
xwininfo -all
xwininfo: Please select the window about which you
would like information by clicking the
mouse in that window.
xwininfo: Window id: 0x3400007 "html : xwininfo — Konsole"
Root window id: 0x752 (the root window) (has no name)
Parent window id: 0x18003b5 (has no name)
0 children.
Absolute upper-left X: 0
Absolute upper-left Y: 29
Relative upper-left X: 0
Relative upper-left Y: 0
Width: 1920
Height: 1005
Depth: 32
Visual: 0x73b
Visual Class: TrueColor
Border width: 0
Class: InputOutput
Colormap: 0x3400006 (not 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: +0+29 -0+29 -0-46 +0-46
-geometry 1920x1005+0+29
Bit gravity: NorthWestGravity
Window gravity: NorthWestGravity
Backing-store hint: NotUseful
Backing-planes to be preserved: 0xffffffff
Backing pixel: 0
Save-unders: No
Someone wants these events:
KeyPress
KeyRelease
ButtonPress
ButtonRelease
EnterWindow
LeaveWindow
PointerMotion
ButtonMotion
Exposure
StructureNotify
FocusChange
PropertyChange
ColormapChange
Do not propagate these events:
Override redirection?: No
Window manager hints:
Client accepts input or input focus: Yes
Initial state is Normal State
Displayed on desktop 0
Window type:
Normal
Window state:
Maximized Vert
Maximized Horz
Focused
Process id: 160622 on host dev-computer
Frame extents: 0, 0, 29, 0
Normal window size hints:
User supplied size: 1920 by 1005
Program supplied minimum size: 65 by 65
Program supplied window gravity: StaticGravity
No zoom window size hints defined
No window shape defined
No border shape defined
那么我们能否直接找到
xwininfo
源码,参考他们的思路呢?
~: apt search xwininfo # 通过平时用的命令查找到包名
Sorting... Done
Full Text Search... Done
x11-utils/stable,now 7.7+5 amd64 [installed,automatic]
X11 utilities
~: apt source x11-utils # 通过包名下载包源码(到当前目录)
Reading package lists... Done
NOTICE: 'x11-utils' packaging is maintained in the 'Git' version control system at:
https://salsa.debian.org/xorg-team/app/x11-utils.git
Please use:
git clone https://salsa.debian.org/xorg-team/app/x11-utils.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 3,059 kB of source archives.
Get:1 https://mirrors.ustc.edu.cn/debian bullseye/main x11-utils 7.7+5 (dsc) [2,136 B]
Get:2 https://mirrors.ustc.edu.cn/debian bullseye/main x11-utils 7.7+5 (tar) [3,057 kB]
Fetched 3,059 kB in 0s (7,412 kB/s)
dpkg-source: info: extracting x11-utils in x11-utils-7.7+5
dpkg-source: info: unpacking x11-utils_7.7+5.tar.gz
~: ls -lah
x11-utils-7.7+5/
x11-utils_7.7+5.dsc
x11-utils_7.7+5.tar.gz
~: grep -rni "Window state" x11-utils-7.7+5 # 根据关键字搜索下载好的源码
x11-utils-7.7+5/xwininfo/xwininfo.c:1736: printf (" Window state:\n");
x11-utils-7.7+5/xprop/xprop.c:376:"\t\twindow state: ?$0=0(Withdrawn)?$0=1(Normal)?$0=3(Iconic)\n"\
~: vim x11-utils-7.7+5/xwininfo/xwininfo.cs
7 if (atom_net_wm_state) {
6 prop = xcb_get_property_reply (dpy, w->wm_state_cookie, NULL);
5 if (prop && (prop->type != XCB_NONE) && (prop->value_len > 0)) {
4 xcb_atom_t *atoms = xcb_get_property_value (prop);
3 int atom_count = prop->value_len;
2
1 if (atom_count > 0) {
1736 printf (" Window state:\n");
1 for (i = 0; i < atom_count; i++)
2 Display_Atom_Name (atoms[i], "_NET_WM_STATE_");
3 }
4 }
5 free (prop);
6 }