应用程序启动时的XNextEvent阻塞
XNextEvent Blocking At Start of Application
我有以下应用程序。
#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监视窗口中的地址提供正确的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
相关文章:
- QTcpSocket在不阻塞GUI的情况下重新连接到服务器
- 如何在调用析构函数时优雅地停止/销毁带有阻塞调用C++线程?
- 为什么创建服务器后C++ httplib 库阻塞了我的主线程?
- 阻塞信号会导致升压过程不起作用
- 避免在条件更新时丢失唤醒是一个阻塞功能
- pthread_kill() 与 pthread_cancel() 终止因 I/O 而阻塞的线程
- 提升 asio io_content运行非阻塞
- 阻塞管道连接命名管道不触发
- 在C++中执行非阻塞线程
- 如果 I/O read() 处于阻塞阶段,如何使用 Ctrl+C 退出 C++ 程序?
- C++17 标准::异步非阻塞执行
- 如何实现阻塞处理循环?
- 不安全的 MPI 非阻塞通信示例?
- 内联asm编译器屏障(内存阻塞器)是算作外部函数,还是算作静态函数调用
- cors 阻塞请求的根源在哪里?
- 用于免等待生产者和阻塞使用者的环形缓冲区
- 被阻塞的互斥量有多贵
- 正在等待在非阻塞文件描述符上长时间运行ioctl
- C++如何判断互斥体在阻塞其他线程时是否被单个线程不成比例地占用
- 应用程序启动时的XNextEvent阻塞