summaryrefslogtreecommitdiff
path: root/plugingui/nativewindow_x11.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-11-29 21:16:43 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2015-11-29 21:16:43 +0100
commit66a51cd2c4474c89bce6a7429bd9b8172f748ac0 (patch)
tree70cf8aaba404e6b91fe4a22806ed03ff75514eb2 /plugingui/nativewindow_x11.cc
parentf59d2329c904e8cb5f6509050444bf2aee4b8f65 (diff)
Fix missing mouse release. Use wswitch in xeven handling.
Diffstat (limited to 'plugingui/nativewindow_x11.cc')
-rw-r--r--plugingui/nativewindow_x11.cc233
1 files changed, 124 insertions, 109 deletions
diff --git a/plugingui/nativewindow_x11.cc b/plugingui/nativewindow_x11.cc
index 02ee653..6330f86 100644
--- a/plugingui/nativewindow_x11.cc
+++ b/plugingui/nativewindow_x11.cc
@@ -367,136 +367,151 @@ Event* NativeWindowX11::peekNextEvent()
XEvent peekXEvent;
XPeekEvent(display, &peekXEvent);
- return translateXMessage(peekXEvent);
+ return translateXMessage(peekXEvent, true);
}
-Event* NativeWindowX11::translateXMessage(XEvent& xevent)
+ Event* NativeWindowX11::translateXMessage(XEvent& xevent, bool peek)
{
Event* event = nullptr;
- if(xevent.type == MotionNotify)
- {
- auto mouseMoveEvent = new MouseMoveEvent();
- mouseMoveEvent->window_id = xevent.xmotion.window;
- mouseMoveEvent->x = xevent.xmotion.x;
- mouseMoveEvent->y = xevent.xmotion.y;
- event = mouseMoveEvent;
- }
-
- if(xevent.type == Expose && xevent.xexpose.count == 0)
- {
- auto repaintEvent = new RepaintEvent();
- repaintEvent->window_id = xevent.xexpose.window;
- repaintEvent->x = xevent.xexpose.x;
- repaintEvent->y = xevent.xexpose.y;
- repaintEvent->width = xevent.xexpose.width;
- repaintEvent->height = xevent.xexpose.height;
- event = repaintEvent;
- }
+ switch(xevent.type) {
+ case MotionNotify:
+ {
+ auto mouseMoveEvent = new MouseMoveEvent();
+ mouseMoveEvent->window_id = xevent.xmotion.window;
+ mouseMoveEvent->x = xevent.xmotion.x;
+ mouseMoveEvent->y = xevent.xmotion.y;
+ event = mouseMoveEvent;
+ }
+ break;
- if(xevent.type == ConfigureNotify)
- {
- auto resizeEvent = new ResizeEvent();
- resizeEvent->window_id = xevent.xconfigure.window;
- //resizeEvent->x = xevent.xconfigure.x;
- //resizeEvent->y = xevent.xconfigure.y;
- resizeEvent->width = xevent.xconfigure.width;
- resizeEvent->height = xevent.xconfigure.height;
- event = resizeEvent;
- }
+ case Expose:
+ if(xevent.xexpose.count == 0)
+ {
+ auto repaintEvent = new RepaintEvent();
+ repaintEvent->window_id = xevent.xexpose.window;
+ repaintEvent->x = xevent.xexpose.x;
+ repaintEvent->y = xevent.xexpose.y;
+ repaintEvent->width = xevent.xexpose.width;
+ repaintEvent->height = xevent.xexpose.height;
+ event = repaintEvent;
+ }
+ break;
- if(xevent.type == ButtonPress || xevent.type == ButtonRelease)
- {
- if((xevent.xbutton.button == 4) || (xevent.xbutton.button == 5))
+ case ConfigureNotify:
{
- int scroll = 1;
- auto scrollEvent = new ScrollEvent();
- scrollEvent->window_id = xevent.xbutton.window;
- scrollEvent->x = xevent.xbutton.x;
- scrollEvent->y = xevent.xbutton.y;
- scrollEvent->delta = scroll * ((xevent.xbutton.button == 4) ? -1 : 1);
- event = scrollEvent;
+ auto resizeEvent = new ResizeEvent();
+ resizeEvent->window_id = xevent.xconfigure.window;
+ //resizeEvent->x = xevent.xconfigure.x;
+ //resizeEvent->y = xevent.xconfigure.y;
+ resizeEvent->width = xevent.xconfigure.width;
+ resizeEvent->height = xevent.xconfigure.height;
+ event = resizeEvent;
}
- else
+ break;
+
+ case ButtonPress:
+ case ButtonRelease:
{
- auto buttonEvent = new ButtonEvent();
- buttonEvent->window_id = xevent.xbutton.window;
- buttonEvent->x = xevent.xbutton.x;
- buttonEvent->y = xevent.xbutton.y;
- switch(xevent.xbutton.button) {
- case 1:
- buttonEvent->button = MouseButton::left;
- break;
- case 2:
- buttonEvent->button = MouseButton::middle;
- break;
- case 3:
- buttonEvent->button = MouseButton::right;
- break;
- default:
- WARN(X11, "Unknown button %d, setting to MouseButton::left\n",
- xevent.xbutton.button);
- buttonEvent->button = MouseButton::left;
- break;
+ if((xevent.xbutton.button == 4) || (xevent.xbutton.button == 5))
+ {
+ int scroll = 1;
+ auto scrollEvent = new ScrollEvent();
+ scrollEvent->window_id = xevent.xbutton.window;
+ scrollEvent->x = xevent.xbutton.x;
+ scrollEvent->y = xevent.xbutton.y;
+ scrollEvent->delta = scroll * ((xevent.xbutton.button == 4) ? -1 : 1);
+ event = scrollEvent;
}
-
- buttonEvent->direction =
- (xevent.type == ButtonPress) ?
- Direction::down : Direction::up;
-
- buttonEvent->doubleClick =
- (xevent.type == ButtonPress) &&
- ((xevent.xbutton.time - last_click) < 200);
-
- if(xevent.type == ButtonPress)
+ else
{
- last_click = xevent.xbutton.time;
+ auto buttonEvent = new ButtonEvent();
+ buttonEvent->window_id = xevent.xbutton.window;
+ buttonEvent->x = xevent.xbutton.x;
+ buttonEvent->y = xevent.xbutton.y;
+ switch(xevent.xbutton.button) {
+ case 1:
+ buttonEvent->button = MouseButton::left;
+ break;
+ case 2:
+ buttonEvent->button = MouseButton::middle;
+ break;
+ case 3:
+ buttonEvent->button = MouseButton::right;
+ break;
+ default:
+ WARN(X11, "Unknown button %d, setting to MouseButton::left\n",
+ xevent.xbutton.button);
+ buttonEvent->button = MouseButton::left;
+ break;
+ }
+
+ buttonEvent->direction =
+ (xevent.type == ButtonPress) ?
+ Direction::down : Direction::up;
+
+ buttonEvent->doubleClick =
+ (xevent.type == ButtonPress) &&
+ ((xevent.xbutton.time - last_click) < 200);
+
+ if(!peek && (xevent.type == ButtonPress))
+ {
+ last_click = xevent.xbutton.time;
+ }
+ event = buttonEvent;
}
- event = buttonEvent;
}
- }
+ break;
- if(xevent.type == KeyPress || xevent.type == KeyRelease)
- {
- auto keyEvent = new KeyEvent();
- keyEvent->window_id = xevent.xkey.window;
-
- switch(xevent.xkey.keycode) {
- case 113: keyEvent->keycode = Key::left; break;
- case 114: keyEvent->keycode = Key::right; break;
- case 111: keyEvent->keycode = Key::up; break;
- case 116: keyEvent->keycode = Key::down; break;
- case 119: keyEvent->keycode = Key::deleteKey; break;
- case 22: keyEvent->keycode = Key::backspace; break;
- case 110: keyEvent->keycode = Key::home; break;
- case 115: keyEvent->keycode = Key::end; break;
- case 117: keyEvent->keycode = Key::pageDown; break;
- case 112: keyEvent->keycode = Key::pageUp; break;
- case 36: keyEvent->keycode = Key::enter; break;
- default: keyEvent->keycode = Key::unknown; break;
- }
+ case KeyPress:
+ case KeyRelease:
+ {
+ auto keyEvent = new KeyEvent();
+ keyEvent->window_id = xevent.xkey.window;
+
+ switch(xevent.xkey.keycode) {
+ case 113: keyEvent->keycode = Key::left; break;
+ case 114: keyEvent->keycode = Key::right; break;
+ case 111: keyEvent->keycode = Key::up; break;
+ case 116: keyEvent->keycode = Key::down; break;
+ case 119: keyEvent->keycode = Key::deleteKey; break;
+ case 22: keyEvent->keycode = Key::backspace; break;
+ case 110: keyEvent->keycode = Key::home; break;
+ case 115: keyEvent->keycode = Key::end; break;
+ case 117: keyEvent->keycode = Key::pageDown; break;
+ case 112: keyEvent->keycode = Key::pageUp; break;
+ case 36: keyEvent->keycode = Key::enter; break;
+ default: keyEvent->keycode = Key::unknown; break;
+ }
- char stringBuffer[1024];
- int size = XLookupString(&xevent.xkey, stringBuffer,
+ char stringBuffer[1024];
+ int size = XLookupString(&xevent.xkey, stringBuffer,
sizeof(stringBuffer), nullptr, nullptr);
- if(size && keyEvent->keycode == Key::unknown)
- {
- keyEvent->keycode = Key::character;
- }
+ if(size && keyEvent->keycode == Key::unknown)
+ {
+ keyEvent->keycode = Key::character;
+ }
- keyEvent->text.append(stringBuffer, size);
+ keyEvent->text.append(stringBuffer, size);
- keyEvent->direction =
- (xevent.type == KeyPress) ? Direction::down : Direction::up;
+ keyEvent->direction =
+ (xevent.type == KeyPress) ? Direction::down : Direction::up;
- event = keyEvent;
- }
+ event = keyEvent;
+ }
+ break;
- if((xevent.type == ClientMessage) &&
- ((unsigned int)xevent.xclient.data.l[0] == wmDeleteMessage))
- {
- auto closeEvent = new CloseEvent();
- event = closeEvent;
+ case ClientMessage:
+ if(((unsigned int)xevent.xclient.data.l[0] == wmDeleteMessage))
+ {
+ auto closeEvent = new CloseEvent();
+ event = closeEvent;
+ }
+ break;
+
+ default:
+ WARN(X11, "Unhandled xevent.type: %d\n", xevent.type);
+ break;
}
return event;