我使用下面的相关代码创建一个xlib窗口。当我尝试移动窗口时,光标会短暂地变为抓取光标,我无法拖动窗口。但是,如果我将焦点更改为另一个应用程序,然后返回到我的应用程序,我可以拖动窗口。我是xlib的新手,不明白为什么我不能在创建后拖动窗口?
ms_display = XOpenDisplay(NULL);
int screen = DefaultScreen(ms_display);
Window rootWindow = RootWindow(ms_display,screen);
XSetWindowAttributes windowAttrib;
windowAttrib.background_pixel = 0;
windowAttrib.border_pixel = 0;
windowAttrib.colormap = XCreateColormap(ms_display,rootWindow,m_visual,AllocNone);
windowAttrib.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | PointerMotionMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask;
int width = m_displayInfo.m_windowWidth;
int height = m_displayInfo.m_windowHeight;
unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
ms_window = XCreateWindow(ms_display,rootWindow,0,0,width,height, 0, pVisInfo->depth,
InputOutput,pVisInfo->visual,mask,&windowAttrib);
XMapWindow(ms_display, ms_window);
XFlush(ms_display);
XSizeHints sizeHints;
sizeHints.x = (WidthOfScreen(ScreenOfDisplay(ms_display, screen)) - width) / 2;
sizeHints.y = (HeightOfScreen(ScreenOfDisplay(ms_display, screen)) - height) / 2;
sizeHints.width = width;
sizeHints.height = height;
sizeHints.flags = USPosition | USSize;
XSetWMSizeHints(ms_display,ms_window,&sizeHints,XInternAtom(ms_display,"WM_SIZE_HINTS",False));
XMoveResizeWindow(ms_display,ms_window,sizeHints.x,sizeHints.y,width,height);
答案 0 :(得分:0)
我确实碰到了一种类似的情况,即在我调用XSetWMHints()之前,新创建的窗口无法获得焦点,接收鼠标点击或键盘输入,即使是完全空的结构,例如以下内容足以让它发挥作用:
XWMHints xwmh;
xwmh.flags = 0;
XSetWMHints (m_display, m_window, &xwmh);
很奇怪,但它解决了我的问题。