From 0f2398d1f622cce37925f52d978d92e6cce1c7a9 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Tue, 9 Mar 2021 11:24:11 -0500 Subject: making mouse movements only reported to widgets in raleigh if they request it, and making it continue while the mouse is outside the widget (but inside the window) --- src/user/raleigh/window.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/user/raleigh/window.cpp') diff --git a/src/user/raleigh/window.cpp b/src/user/raleigh/window.cpp index 8501f7e..b99346d 100644 --- a/src/user/raleigh/window.cpp +++ b/src/user/raleigh/window.cpp @@ -7,7 +7,7 @@ namespace raleigh { window::window(widget &root, _pixel_t bg_color, bool (*on_close)(window &)) : handle(0), size(root.size), root(root), focussed(&root), - bg_color(bg_color), on_close(on_close) { + drag_reciever(0), bg_color(bg_color), on_close(on_close) { root.w = this; root.window_offset = coord(0, 0); root.notify_window_change(); @@ -41,8 +41,11 @@ namespace raleigh { got = GOOD; if (wa.action_type == wa.MOUSE_DOWN) root.handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, false); - else if (wa.action_type == wa.MOUSE_UP) + else if (wa.action_type == wa.MOUSE_UP) { + if (drag_reciever && (wa.as_mouse.which == drag_until)) + drag_reciever = 0; root.handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, true); + } else if (wa.action_type == wa.KEY_DOWN) { for (dllist>::node *n = keybinds.first; n; n = n->next) if (match_side_agnostic(wa.as_key, n->d.a)) { @@ -57,8 +60,8 @@ namespace raleigh { focussed->on_focus(); else if (wa.action_type == wa.FOCUS_LEAVE) focussed->on_unfocus(); - else if (wa.action_type == wa.MOUSE_MOVE) - root.on_mouse_move(coord(wa.moved_to.x, wa.moved_to.y)); + else if (drag_reciever && (wa.action_type == wa.MOUSE_MOVE)) + drag_reciever->on_mouse_move(coord(wa.moved_to.x, wa.moved_to.y)); } } @@ -112,4 +115,9 @@ namespace raleigh { void window::add_keybind(struct key_packet kp, void (*handler)(window &)) { keybinds.add_front(duple(kp, handler)); } + + void window::notify_wants_movements(widget &from, enum mouse_packet::mouse_button while_down) { + drag_reciever = &from; + drag_until = while_down; + } } \ No newline at end of file -- cgit v1.2.3