gpt4 book ai didi

c++ - XNextEvent 在应用程序开始时阻塞

转载 作者:太空狗 更新时间:2023-10-29 12:20:47 25 4
gpt4 key购买 nike

我有以下应用程序。

#include <FWWindow.h>
#include <FWApplication.h>

int main(int /*argc*/, char */*argv*/[])
{
FWApplication::Initialize();
FWWindow *win = new FWWindow(800, 600);
win->Show();
FWApplication::Run();
delete win;
}

当我运行它时,它会卡在 XNextEvent() 上,因为它会阻塞,直到它从 XServer 获取下一个事件。我想知道的是,基于下面的代码,为什么 XNextEvent 在我调用 XMapWindow() 后没有获得 ConfigureNotify 或 Expose 事件;我已检查以确保我的应用程序根据我的 IDE 监 window 口中的地址提供正确的 Display。我缺少什么才能让窗口出现?


Initialize() does the following

-

FWApplication *FWApplication::Initialize()
{
if (!_instance)
{
_xDisplay = XOpenDisplay(NULL);
if (_xDisplay == NULL)
throw "Failed to get XDisplay";
_initialized = true;
_instance = new FWApplication(); // Calls an empty ctor
}
return _instance;
}

FWWindow *win = new FWWindow(800, 600); does the following

-

FWWindow::FWWindow(int width, int height) :
clientWidth(width),
clientHeight(height)
{
// These are all member variables
xDisplay = FWApplication::GetMainDisplay();
xScreen = DefaultScreen(xDisplay);
xDepth = DefaultDepth(xDisplay, xScreen);
xVisual = DefaultVisual(xDisplay,xScreen);
xAttributes.background_pixel = XWhitePixel(xDisplay, xScreen);
xAttributes.border_pixel = XBlackPixel(xDisplay, xScreen);
xAttributes.override_redirect = 0;
xWindow = XCreateWindow(
xDisplay,
RootWindow(xDisplay, xScreen),
0, 0,
width, height,
0,
xDepth,
InputOutput,
xVisual,
CWBorderPixel | CWColormap | CWEventMask,
&xAttributes
);

XSetStandardProperties(
xDisplay,
xWindow,
"glxsimple",
"glxsimple",
None,
NULL,
0,
NULL
);
}

win->Show(); does the following

-

void FWWindow::Show()
{
XMapWindow(xDisplay, xWindow); // xWindow and xDisplay defined in ctor above
}

And finaly FWApplication::Run(); does the following

-

int FWApplication::Run()
{
if (!_initialized)
return -1;
static bool run = true;
static Display *lDisplay = _xDisplay;
XEvent xEvent;
while (run)
{
do
{
XNextEvent(lDisplay, &xEvent);
switch (xEvent.type)
{
case ConfigureNotify:
{
unsigned int w = xEvent.xconfigure.width;
unsigned int h = xEvent.xconfigure.height;
// Do something to main widget
}
case Expose:
break;
}
} while (XPending(GetMainDisplay()));
}
return EXIT_SUCCESS;
}

最佳答案

您没有在窗口的属性中指定事件掩码,因此 XNextEvent() 不会报告任何事件。你应该这样写:

xAttributes.background_pixel = XWhitePixel(xDisplay, xScreen);
xAttributes.border_pixel = XBlackPixel(xDisplay, xScreen);
xAttributes.override_redirect = 0;
xAttributes.event_mask = StructureNotifyMask // for ConfigureNotify
| ExposureMask; // for Expose

关于c++ - XNextEvent 在应用程序开始时阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9347214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com