Linux X11 鼠标移动事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9357382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
X11 Mouse Movement Event
提问by Matthew Hoggan
When creating a Window in XLib
在 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?
- 我提供给
SetWindowAttributes.event_mask
会员的口罩是什么? - 我有什么要传递给第 11 个参数的
XCreateWindow()
- 我在主消息循环中寻找的事件是什么(我在哪里使用
XNextEvent(lDisplay, &xEvent);
? - 由于 X 的行为与 Microsoft 的 Win32 API 不同,我如何确定鼠标是在我的窗口上还是在我的“应用程序”中的窗口上,而不是在桌面上?
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-3 部分的人:
1.
1.
xAttributes.event_mask = ExposureMask | KeyPressMask | ButtonPress |
StructureNotifyMask | ButtonReleaseMask |
KeyReleaseMask | EnterWindowMask | LeaveWindowMask |
PointerMotionMask | Button1MotionMask | VisibilityChangeMask |
ColormapChangeMask;
2.
2.
unsigned long valuemask = CWEventMask | CWBackPixel | CWBorderPixel | CWCursor;
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; }
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; }
采纳答案by Jim Garrison
XLib is pretty well documented. For example XLib Programming Manual: Event Masks
XLib 有很好的文档记录。例如XLib 编程手册:事件掩码
回答by Simon Richter
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.
要确定鼠标是否在您的窗口上,请收听 Enter 和 Leave 事件。该xev
实用程序是了解 X 窗口系统中存在哪些事件以及何时发送事件的好方法。