mirror of https://github.com/buggins/dlangui.git
fix mouse processing
This commit is contained in:
parent
f1b4efe6eb
commit
5b358236f2
|
@ -113,7 +113,17 @@ class Window {
|
||||||
protected Widget _mouseTrackingWidget;
|
protected Widget _mouseTrackingWidget;
|
||||||
/// widget which tracks all events after processed ButtonDown
|
/// widget which tracks all events after processed ButtonDown
|
||||||
protected Widget _mouseCaptureWidget;
|
protected Widget _mouseCaptureWidget;
|
||||||
|
protected ushort _mouseCaptureButtons;
|
||||||
protected bool _mouseCaptureFocusedOut;
|
protected bool _mouseCaptureFocusedOut;
|
||||||
|
|
||||||
|
protected bool dispatchCancel(MouseEvent event) {
|
||||||
|
event.changeAction(MouseAction.Cancel);
|
||||||
|
bool res = _mouseCaptureWidget.onMouseEvent(event);
|
||||||
|
_mouseCaptureWidget = null;
|
||||||
|
_mouseCaptureFocusedOut = false;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/// dispatch mouse event to window content widgets
|
/// dispatch mouse event to window content widgets
|
||||||
bool dispatchMouseEvent(MouseEvent event) {
|
bool dispatchMouseEvent(MouseEvent event) {
|
||||||
// ignore events if there is no root
|
// ignore events if there is no root
|
||||||
|
@ -127,23 +137,29 @@ class Window {
|
||||||
_mouseTrackingWidget = null;
|
_mouseTrackingWidget = null;
|
||||||
|
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
ushort currentButtons = event.flags & (MouseFlag.LButton|MouseFlag.RButton|MouseFlag.MButton);
|
||||||
if (_mouseCaptureWidget !is null) {
|
if (_mouseCaptureWidget !is null) {
|
||||||
// try to forward message directly to active widget
|
// try to forward message directly to active widget
|
||||||
if (event.action == MouseAction.Move) {
|
if (event.action == MouseAction.Move) {
|
||||||
if (!_mouseCaptureWidget.isPointInside(event.x, event.y)) {
|
if (!_mouseCaptureWidget.isPointInside(event.x, event.y)) {
|
||||||
|
if (currentButtons != _mouseCaptureButtons)
|
||||||
|
return dispatchCancel(event);
|
||||||
// point is no more inside of captured widget
|
// point is no more inside of captured widget
|
||||||
if (!_mouseCaptureFocusedOut) {
|
if (!_mouseCaptureFocusedOut) {
|
||||||
// sending FocusOut message
|
// sending FocusOut message
|
||||||
event.changeAction(MouseAction.FocusOut);
|
event.changeAction(MouseAction.FocusOut);
|
||||||
_mouseCaptureFocusedOut = true;
|
_mouseCaptureFocusedOut = true;
|
||||||
|
_mouseCaptureButtons = event.flags & (MouseFlag.LButton|MouseFlag.RButton|MouseFlag.MButton);
|
||||||
return _mouseCaptureWidget.onMouseEvent(event);
|
return _mouseCaptureWidget.onMouseEvent(event);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// point is inside widget
|
// point is inside widget
|
||||||
if (_mouseCaptureFocusedOut) {
|
if (_mouseCaptureFocusedOut) {
|
||||||
event.changeAction(MouseAction.FocusIn); // back in after focus out
|
|
||||||
_mouseCaptureFocusedOut = false;
|
_mouseCaptureFocusedOut = false;
|
||||||
|
if (currentButtons != _mouseCaptureButtons)
|
||||||
|
return dispatchCancel(event);
|
||||||
|
event.changeAction(MouseAction.FocusIn); // back in after focus out
|
||||||
}
|
}
|
||||||
return _mouseCaptureWidget.onMouseEvent(event);
|
return _mouseCaptureWidget.onMouseEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -152,6 +168,7 @@ class Window {
|
||||||
// sending FocusOut message
|
// sending FocusOut message
|
||||||
event.changeAction(MouseAction.FocusOut);
|
event.changeAction(MouseAction.FocusOut);
|
||||||
_mouseCaptureFocusedOut = true;
|
_mouseCaptureFocusedOut = true;
|
||||||
|
_mouseCaptureButtons = event.flags & (MouseFlag.LButton|MouseFlag.RButton|MouseFlag.MButton);
|
||||||
return _mouseCaptureWidget.onMouseEvent(event);
|
return _mouseCaptureWidget.onMouseEvent(event);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -34,24 +34,6 @@ version(linux) {
|
||||||
Log.d("Destroying window");
|
Log.d("Destroying window");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// request window redraw
|
|
||||||
override void invalidate() {
|
|
||||||
|
|
||||||
xcb_expose_event_t * event = cast(xcb_expose_event_t*)std.c.stdlib.malloc(xcb_expose_event_t.sizeof);
|
|
||||||
event.response_type = XCB_EXPOSE; /* The type of the event, here it is XCB_EXPOSE */
|
|
||||||
event.sequence = 0;
|
|
||||||
event.window = _w; /* The Id of the window that receives the event (in case */
|
|
||||||
/* our application registered for events on several windows */
|
|
||||||
event.x = 0; /* The x coordinate of the top-left part of the window that needs to be redrawn */
|
|
||||||
event.y = 0; /* The y coordinate of the top-left part of the window that needs to be redrawn */
|
|
||||||
event.width = cast(ushort)_dx; /* The width of the part of the window that needs to be redrawn */
|
|
||||||
event.height = cast(ushort)_dy; /* The height of the part of the window that needs to be redrawn */
|
|
||||||
event.count = 1;
|
|
||||||
|
|
||||||
xcb_void_cookie_t res = xcb_send_event(_xcbconnection, false, _w, XCB_EVENT_MASK_EXPOSURE, cast(char *)event);
|
|
||||||
xcb_flush(_xcbconnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool create() {
|
bool create() {
|
||||||
uint mask;
|
uint mask;
|
||||||
uint values[2];
|
uint values[2];
|
||||||
|
@ -209,8 +191,30 @@ version(linux) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorDrawBuf _drawbuf;
|
ColorDrawBuf _drawbuf;
|
||||||
|
bool _exposeSent;
|
||||||
void processExpose(xcb_expose_event_t * event) {
|
void processExpose(xcb_expose_event_t * event) {
|
||||||
redraw();
|
redraw();
|
||||||
|
_exposeSent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// request window redraw
|
||||||
|
override void invalidate() {
|
||||||
|
if (_exposeSent)
|
||||||
|
return;
|
||||||
|
_exposeSent = true;
|
||||||
|
xcb_expose_event_t * event = cast(xcb_expose_event_t*)std.c.stdlib.malloc(xcb_expose_event_t.sizeof);
|
||||||
|
event.response_type = XCB_EXPOSE; /* The type of the event, here it is XCB_EXPOSE */
|
||||||
|
event.sequence = 0;
|
||||||
|
event.window = _w; /* The Id of the window that receives the event (in case */
|
||||||
|
/* our application registered for events on several windows */
|
||||||
|
event.x = 0; /* The x coordinate of the top-left part of the window that needs to be redrawn */
|
||||||
|
event.y = 0; /* The y coordinate of the top-left part of the window that needs to be redrawn */
|
||||||
|
event.width = cast(ushort)_dx; /* The width of the part of the window that needs to be redrawn */
|
||||||
|
event.height = cast(ushort)_dy; /* The height of the part of the window that needs to be redrawn */
|
||||||
|
event.count = 1;
|
||||||
|
|
||||||
|
xcb_void_cookie_t res = xcb_send_event(_xcbconnection, false, _w, XCB_EVENT_MASK_EXPOSURE, cast(char *)event);
|
||||||
|
xcb_flush(_xcbconnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ButtonDetails _lbutton;
|
protected ButtonDetails _lbutton;
|
||||||
|
@ -238,14 +242,20 @@ version(linux) {
|
||||||
case 1:
|
case 1:
|
||||||
button = MouseButton.Left;
|
button = MouseButton.Left;
|
||||||
pbuttonDetails = &_lbutton;
|
pbuttonDetails = &_lbutton;
|
||||||
|
if (action == MouseAction.ButtonDown)
|
||||||
|
flags |= MouseFlag.LButton;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
button = MouseButton.Middle;
|
button = MouseButton.Middle;
|
||||||
pbuttonDetails = &_mbutton;
|
pbuttonDetails = &_mbutton;
|
||||||
|
if (action == MouseAction.ButtonDown)
|
||||||
|
flags |= MouseFlag.MButton;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
button = MouseButton.Right;
|
button = MouseButton.Right;
|
||||||
pbuttonDetails = &_rbutton;
|
pbuttonDetails = &_rbutton;
|
||||||
|
if (action == MouseAction.ButtonDown)
|
||||||
|
flags |= MouseFlag.RButton;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
if (action == MouseAction.ButtonUp)
|
if (action == MouseAction.ButtonUp)
|
||||||
|
@ -464,8 +474,14 @@ version(linux) {
|
||||||
}
|
}
|
||||||
case XCB_LEAVE_NOTIFY: {
|
case XCB_LEAVE_NOTIFY: {
|
||||||
xcb_leave_notify_event_t *leave = cast(xcb_leave_notify_event_t *)e;
|
xcb_leave_notify_event_t *leave = cast(xcb_leave_notify_event_t *)e;
|
||||||
|
|
||||||
Log.d("XCB_LEAVE_NOTIFY ", leave.event, " at coords ", leave.event_x, ", ", leave.event_y);
|
Log.d("XCB_LEAVE_NOTIFY ", leave.event, " at coords ", leave.event_x, ", ", leave.event_y);
|
||||||
|
XCBWindow window = getWindow(leave.event);
|
||||||
|
if (window !is null) {
|
||||||
|
//
|
||||||
|
window.processMouseEvent(MouseAction.Leave, 0, leave.state, leave.event_x, leave.event_y);
|
||||||
|
} else {
|
||||||
|
Log.w("Received message for unknown window", leave.event);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case XCB_KEY_PRESS: {
|
case XCB_KEY_PRESS: {
|
||||||
|
|
|
@ -145,7 +145,7 @@ class Button : Widget {
|
||||||
Log.d("Button state: ", state);
|
Log.d("Button state: ", state);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (event.action == MouseAction.FocusOut) {
|
if (event.action == MouseAction.FocusOut || event.action == MouseAction.Cancel) {
|
||||||
resetState(State.Pressed);
|
resetState(State.Pressed);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue