X11 鼠标移动事件
在 XLib 中创建窗口时
- 我向
SetWindowAttributes.event_mask
成员提供的掩码是什么? - 我必须将什么传递给 XCreateWindow() 的第 11 个参数
- 我在主消息循环中查找的事件是什么(我使用 XNextEvent(lDisplay, &xEvent); 的地方) ?
- 由于 X 的行为与 Microsoft 的 Win32 API 不同,我如何确定鼠标是否位于我的窗口或“应用程序”中的窗口而不是桌面上
?已经 指出我的方向。
对于那些想要第 1-3 部分的简单答案的人,
2.
xAttributes.event_mask = ExposureMask | KeyPressMask | ButtonPress |
StructureNotifyMask | ButtonReleaseMask |
KeyReleaseMask | EnterWindowMask | LeaveWindowMask |
PointerMotionMask | Button1MotionMask | VisibilityChangeMask |
ColormapChangeMask;
请
unsigned long valuemask = CWEventMask | CWBorderPixel | CWBorderPixel ;
开关 (xEvent.type) { 案例MapNotify: 休息; 案例曝光: // 如果这不是最后一次公开事件中断 if (xEvent.xexpose.count != 0) 休息; 别的 休息; 案例配置通知: 休息; 案例可见性通知: 休息; 案例销毁通知: 休息; 案例按钮按下: 案例按钮释放: 案例 EnterNotify: 案例MotionNotify: 案例离开通知: 如果(_mouseHandler) _mouseHandler->HandleInput(lDisplay, &xEvent); 休息; 案例按键: 案例密钥发布: if(_keyboardHandler) _keyboardHandler->HandleInput(lDisplay, &xEvent); 休息; 默认: if(_keyboardHandler) _keyboardHandler->HandleInput(lDisplay, &xEvent); 休息; }
When creating a Window in XLib
- What are the masks I provide to the
SetWindowAttributes.event_mask
member? - What do I have to pass to the 11th paramater of
XCreateWindow()
- What are the Events I am looking for in the main message loop (Where I use
XNextEvent(lDisplay, &xEvent);
? - Since X behaves differently than Microsoft's Win32 API, how do I determine if the mouse is over my window or a window in my "Application" and not over the desktop?
I have looked for a similar post. If there is already one out there please point me in the right direction.
Update
For those who want the easy answer to parts 1-3:
1.
xAttributes.event_mask = ExposureMask | KeyPressMask | ButtonPress |
StructureNotifyMask | ButtonReleaseMask |
KeyReleaseMask | EnterWindowMask | LeaveWindowMask |
PointerMotionMask | Button1MotionMask | VisibilityChangeMask |
ColormapChangeMask;
2.
unsigned long valuemask = CWEventMask | CWBackPixel | CWBorderPixel | CWCursor;
switch (xEvent.type) { case MapNotify: break; case Expose: // If this is not the last expose event break if (xEvent.xexpose.count != 0) break; else break; case ConfigureNotify: break; case VisibilityNotify: break; case DestroyNotify: break; case ButtonPress: case ButtonRelease: case EnterNotify: case MotionNotify: case LeaveNotify: if(_mouseHandler) _mouseHandler->HandleInput(lDisplay, &xEvent); break; case KeyPress: case KeyRelease: if(_keyboardHandler) _keyboardHandler->HandleInput(lDisplay, &xEvent); break; default: if(_keyboardHandler) _keyboardHandler->HandleInput(lDisplay, &xEvent); break; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
XLib 有很好的文档记录。例如 XLib 编程手册:事件掩码
XLib is pretty well documented. For example XLib Programming Manual: Event Masks
我认为前三个都有详细记录。
要确定鼠标是否位于窗口上方,请侦听 Enter 和 Leave 事件。
xev
实用程序是了解 X 窗口系统中存在哪些事件以及何时发送这些事件的好方法。The first three are well-documented, I think.
To determine whether the mouse is over your window, listen to Enter and Leave events. The
xev
utility is a great way to understand what events exist in the X window system, and when they are sent.