我对X11编程很陌生。
我尝试了以下代码来显示创建的新窗口的窗口ID,但它显示两次窗口ID(不同的窗口ID)。我正在使用FVWM(fvwm套接字)创建的每个新窗口都是正确的。如果我从命令启动firefox,那么它会显示大约5次窗口。
我想为每个新窗口创建一次正确的窗口ID,而不是两次。
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
int main()
{
Display* display = XOpenDisplay(":0");
XSetWindowAttributes attributes;
// attributes.event_mask = SubstructureNotifyMask | StructureNotifyMask;
attributes.event_mask = SubstructureNotifyMask | VisibilityChangeMask | EnterWindowMask;
attributes.backing_store = Always;
Window win = XDefaultRootWindow(display);
printf("Deafult root window %x\n", win);
XChangeWindowAttributes(display, win, CWEventMask, &attributes);
while (1)
{
XEvent event;
XNextEvent(display, &event);
if (event.type == CreateNotify)
{
puts("create Notify event occured\n");
printf("Window ID: %x\n", event.xcreatewindow.window);
printf("Window ID: %d\n", event.xcreatewindow.window);
printf("Parent Window ID: %x\n", event.xcreatewindow.parent);
}
}
}
以下是“xclock”的输出。
[root@localhost src]# ./XWindow.out
create Notify event occured
Window ID: 3e0000c
Window ID: 65011724
create Notify event occured
Window ID: 100118f
Window ID: 16781711
create Notify event occured
以下是从“xprop”命令
符合相同的内容[root@localhost src]# xclock &
[2] 6564
[root@localhost src]# xprop
_NET_WM_STATE(ATOM) =
WM_STATE(WM_STATE):
window state: Normal
icon window: 0x0
_NET_WM_DESKTOP(CARDINAL) = 0
_NET_FRAME_EXTENTS(CARDINAL) = 1, 1, 39, 1
_NET_WM_ALLOWED_ACTIONS(ATOM) = _NET_WM_ACTION_MOVE, _NET_WM_ACTION_RESIZE, _NET_WM_ACTION_FULLSCREEN, _NET_WM_ACTION_MINIMIZE, _NET_WM_ACTION_SHADE, _NET_WM_ACTION_MAXIMIZE_HORZ, _NET_WM_ACTION_MAXIMIZE_VERT, _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_CLOSE, _NET_WM_ACTION_ABOVE, _NET_WM_ACTION_BELOW
_NET_WM_PID(CARDINAL) = 6564
WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW
SM_CLIENT_ID(STRING) = "10b83f0cefdd07ca73150167045190887900000031930078"
WM_CLIENT_LEADER(WINDOW): window id # 0x3e0000c
WM_LOCALE_NAME(STRING) = "C"
WM_CLASS(STRING) = "xclock", "XClock"
WM_HINTS(WM_HINTS):
Client accepts input or input focus: False
Initial state is Normal State.
bitmap id # to use for icon: 0x3e00001
bitmap id # of mask for icon: 0x3e00003
WM_NORMAL_HINTS(WM_SIZE_HINTS):
program specified size: 164 by 164
window gravity: NorthWest
WM_CLIENT_MACHINE(STRING) = "localhost.localdomain"
WM_COMMAND(STRING) = { "xclock" }
WM_ICON_NAME(STRING) = "xclock"
WM_NAME(STRING) = "xclock"
[root@localhost src]#
在Linux中只创建一个新窗口(例如xclock或firefox)时,您是否知道显示Window id的代码段。
答案 0 :(得分:0)
大多数窗口管理员重新设置新的顶层窗口来管理边框/顶部栏/按钮。我很确定你看到的是应用程序窗口id + wm窗口id。您可以通过查看窗口的所有者pid来检查它 - 它位于_NET_WM_PID poroperty(label1
)中 - 请参阅How to convert a X11 window id to a process id